Sortable columns Joomla - php

I'm developing a MVC component for Joomla! 2.5 and I want to add some sortable columns in my backend. For this goal I've tried to do the next:
http://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component
And I got an error "View not found [name, type, prefix]". In this case I have looking for a solution and I find the next:
http://forum.joomla.org/viewtopic.php?p=2638695
Following those indications I have removed the "action" of my "form". In this case my column is sortable, but another problem arises. If I remove the "action" of my "form" then "edit buttom" of my toolbar does not work.
I think there must be another solution because I need working "edit buttom" and sortable column also. I've looking for some similar question here and I've applied the following information:
How to add sortable columns in a Joomla component (table), both ASC and DESC with an arrow
&
Joomla 2.5 -Adding sortable columns to a table in a component
But my problem persits. What can I do?? Thank you.
MY RELEVANT SOURCE CODE IS THE NEXT:
com_inscripciones/admin/models/anuals.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* Inscripciones List Model
*/
class InscripcionesModelAnuals extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'nombre',
'fecha_nac',
'reserva'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
parent::populateState('id', 'asc');
}
/**
* Method to build an SQL query to load the list data.
*
* #return string An SQL query
*/
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('id,nombre,apellidos,nif,fecha_nac,reserva,validacion,clave');
// From the hello table
$query->from('#__anual');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'nombre')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
}
?>
com_inscripciones/admin/views/anuals/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* Anuals View
*/
class InscripcionesViewAnuals extends JView
{
/**
* display method of Inscripciones view
* #return void
*/
function display($tpl = null)
{
// Get data from the model
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $this->get('State');
$this->sortDirection = $state->get('list.direction');
$this->sortColumn = $state->get('list.ordering');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->items = $items;
$this->pagination = $pagination;
// Set the toolbar
$this->addToolBar();
// Display the template
parent::display($tpl);
}
/**
* Setting the toolbar
*/
protected function addToolBar()
{
JToolBarHelper::title(JText::_('Inscripciones Manager: Curso Anual'), 'inscripciones');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::editList('anual.edit');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::deleteList('¿Desea eliminar esta inscripción?', 'anuals.delete');
JToolBarHelper::spacer('20');
}
}
?>
com_inscripciones/admin/views/anuals/tmpl/default.php
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
?>
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>"method="post" name="adminForm"id="inscripciones-form">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_('ID'); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
</th>
<th>
<?php echo JHtml::_('grid.sort', 'NOMBRE', 'nombre', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JText::_('APELLIDOS'); ?>
</th>
<th>
<?php echo JText::_('NIF'); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'FECHA NAC.', 'fecha_nac', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'RESERVA', 'reserva', $this->sortDirection, $this->sortColumn); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $item->id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo $item->nombre; ?>
</td>
<td>
<?php echo $item->apellidos; ?>
</td>
<td>
<?php echo $item->nif; ?>
</td>
<td>
<?php echo $item->fecha_nac; ?>
</td>
<td>
<?php echo $item->reserva; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>

My query line in model looks like
$query->order($db1->getEscaped($this->getState('list.ordering', 'ordering')).' '.$db1->getEscaped($this->getState('list.direction', 'ASC')));
and populateState contains
$orderCol = JRequest::getCmd('filter_order', 'ordering');
$this->setState('list.ordering', $orderCol);
and the construct on the filter_fields contains
$this->_order[] = JRequest::getVar('filter_order', 'fieldName', 'POST', 'cmd');
$this->_order[] = JRequest::getVar('filter_order_Dir', 'asc', 'POST', 'word');
I had some trouble getting these working in some views in a component I made, just a lot of combinations of things that can be wrong, but you'll get there. I used this tutorial
http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Introduction

I guess you have already found the bug, but for everyone else, based on the provided code:
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>" ...>
This line is wrong. Your view call is &view=anuals$layout=default.
Correct would be &view=anuals&layout=default
The only reason why you got that view error.
Please mark my answer as correct if that was you problem back in 2014.

Related

PHP CodeIgniter Error: Undefined Property [Generate Qrcode]

Hi im new to using additional libraries on codeigniter (im using this library) so these error are really overwhelming me, the goal im trying is to make a form input with option tag (the options from my db) then when i click the button, it will automatically generate the qrcode. at first im following some tutorial from the internet and adjust some parts in order to reach the actual goal.
It doesnt show any explicit error on the html page so i checked the console of the page the error as follows;
jquery-3.4.1.js:9837 POST http://localhost/ikanku/Make_qr/save 500 (Internal Server Error)
send # jquery-3.4.1.js:9837
ajax # jquery-3.4.1.js:9434
(anonymous) # make_qr:421
dispatch # jquery-3.4.1.min.js:2
v.handle # jquery-3.4.1.min.js:2
so im trying to open the network tab to see if there anything that i could fix anything, but it confuse me bcs the error show as following;
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Make_qr::$Ciqrcode
Filename: core/Model.php
Line Number: 73
Backtrace:
File: C:\xampp\xampp\htdocs\ikanku\application\models\Make_qr_model.php
Line: 35
Function: __get
File: C:\xampp\xampp\htdocs\ikanku\application\controllers\Make_qr.php
Line: 24
Function: save
File: C:\xampp\xampp\htdocs\ikanku\index.php
Line: 315
Function: require_once
ive been load the model name, controllers name globally through the autoload and internally through parent::__construct(); but it still error as above, i really need anyone's suggestion/advice for my problem because im still learning on how to make a qrcode feature in my application.
Right now im using CodeIgniter 3.1.11
heres my controller - Make_qr.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Make_qr extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Make_qr_model');
}
public function index()
{
$data['vessel'] = $this->db->query('select * from vessel order by vessel_name')->result_array();
$data['port'] = $this->db->query('select * from port order by port_name')->result_array();
$this->load->view('template/header');
$this->load->view('template/sidebar');
$this->load->view('qrcode/make_qr',$data);
$this->load->view('template/footer');
}
public function save()
{
$this->Make_qr_model->save($this->input->post());
}
}
heres my model - Make_qr_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Make_qr_model extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->library('Ciqrcode');
}
function random_strings($length_of_string){
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //abcdefghijklmnopqrstuvwxyz
return substr(str_shuffle($str_result),0, $length_of_string);
}
//save data function setelah qrcode di generate
public function save($data){
$data = array_replace($data,
array_fill_keys(
array_keys($data, ""),
NULL
)
);
if(isset($data['quantity']) && count($data['quantity'])>0){
for($i=1;$i<=$data['quantity'];$i++){
$r = $this->random_strings(6);
$this->load->library('Ciqrcode');
$config['cacheable'] = true;
$config['cachedir'] = './assets/';
$config['errorlog'] = './assets/';
$config['imagedir'] = './assets/images/';
$config['quality'] = true;
$config['size'] = '1024';
$config['black'] = array(224,255,255);
$config['white'] = array(70,130,180);
$this->Ciqrcode->initialize($config);
$image_name=$r.'.png'; //buat name dari qr code sesuai dengan random string
$params['data'] = $r; //data yang akan di jadikan QR CODE
$params['level'] = 'H'; //H=High
$params['size'] = 1024;
$params['savename'] = FCPATH.$config['imagedir'].$image_name; //simpan image QR CODE ke folder assets/images/
$this->Ciqrcode->generate($params); // fungsi untuk generate QR CODE
$img = file_get_contents(FCPATH.$config['imagedir'].$image_name, "r");
$base64 = 'data:image/png;base64,'.base64_encode($img);
$data_insert = array();
$data_insert['vessel_id'] = $data['vessel_id'];
$data_insert['port_id'] = $data['port_id'];
$data_insert['key'] = $r;
$data_insert['qr'] = $base64;
$this->db->insert('qr_vessel', $data_insert);
$vessel = $this->db->query('select * from vessel where id='.$data['vessel_id'])->row_array();
echo "<table class='table table-striped m-table'>
<tbody>
<tr>
<td width='30%' style='background-color:black'>
<img src=".$base64.">
</td>
<td width='70%' style='vertical-align:top'>
Vessel Name : ".$vessel['vessel_name']."<br>
Vessel Company : ".$vessel['company']."<br>
Fishing Gear : ".$vessel['fishing_gear']."<br>
</td>
</tr>
<tr>
<td align='center'>
".$r."
</td>
<td align='center'></td>
</tr>
</body>
</table>";
}
$notif['x'] = 'ok';
}else{
$notif['x'] = 'error';
die('error');
}
return;
}
}
?>
and heres my view - make_qr.php
<section class="content">
<form role="form" name="frm" action="<?=site_url('Make_qr/save')?>" method="post" id="frm">
<div id="container">
<h1>Generate Fishing QR</h1>
<div id="body">
<table class="table table-striped m-table">
<tbody>
<tr>
<td>Vessel</td>
<td>
<select id='vessel_id' name='vessel_id' style="width:250px" >
<option value="">Pilih</option>
<?php
foreach($vessel as $row){
?>
<option value="<?=$row['id_vessel']?>"><?=$row['vessel_name']?> - <?=$row['company']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Port Departure</td>
<td>
<select id='port_id' name='port_id' style="width:250px" >
<option value="">Pilih</option>
<?php
foreach($port as $row){
?>
<option value="<?=$row['id_port']?>"><?=$row['port_name']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>QR Quantity</td>
<td>
<select id='quantity' name='quantity'>
<option value="">Pilih</option>
<?php
for($i=1;$i<=20;$i++){
?>
<option value="<?=$i?>"><?=$i?></option>
<?php
}
?>
</select>
</td>
</tr>
</tbody>
</table>
<div class="col-lg-3 m--margin-bottom-10-tablet-and-mobile">
<span id='loading' style="display:none"><img src="<?php echo base_url(); ?>Assets/assets/images/ajax-loader_dark.gif"></span>
<button type="button" class="btn btn-info" id="save">Generate</button>
</div>
<br>
<div id='qrs'></div>
</div>
</section>
i apologize for the long description of my errors it would be mean so much to me if i can get some advice & suggestion from here,
thankyou
Change model name Make_qr_model to Makeqr_model
Load library $this->load->model('Makeqr_model');
Load CodeIgniter-PHP-QR-Code library properly; clone git repo and paste folder inside application/libraries
Make sure GD2 PHP extension installed
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRGenerator extends CI_Controller {
function __construct(){
Parent::__construct();
}
public function generate(){
$this->load->library('ciqrcode');
$params['data'] = 'This is a text to encode become QR Code';
$params['level'] = 'H';
$params['size'] = 10;
$params['savename'] = FCPATH.'tes.png';
$this->ciqrcode->generate($params);
echo '<img src="'.base_url().'test.png" />';
}
}
Codeigniter model reference click
Hope it will help you

update table row and save in database in php codeigniter

I am making a table from a database and want to add an Edit/delete button to each row update or delete a specific row from the database. I have successfully added working "delete" button but I have no idea how could I update data in table <td> in view and send it to controller.
Here is my code:
view file
<table class="table table-striped">
<tr>
<td>name</td>
<td>age</td>
<td>gender</td>
<td>class</td>
<td>roll no.</td>
</tr>
<?php foreach($record as $r): ?>
<tr>
<td><?php echo $r->name; ?></td>
<td><?php echo $r->age; ?></td>
<td><?php echo $r->gender; ?></td>
<td><?php echo $r->class; ?></td>
<td><?php echo $r->roll no; ?></td>
<td><a href="" >Edit</a>
<a href="<?php echo base_url()."student/deleteRow" ?id="$r->name">"
onclick="return confirm
('Are you sure to Delete?')"><i class="icon-trash"></a></td>
</tr>
<?php endforeach; ?>
</table>
Controller Function
public function deleteRow(){
if(isset($_GET['id'])){
$id=$this->input->get('id');
$this->student_model->rowDelete($id);
redirect($_SERVER['HTTP_REFERER']);
}
}
I don't know how can I now insert an input field to update table row without effecting previous view. Any suggestion would be helpful.
To Edit the Studen data you need to pass an id or uniue column name to the data base to get that student data.
First Set the student id in <a href=""> tag.
<td><a href="<?= base_url('student/edit_student') ?>/$r->id" >Edit</a>
Then When you click on the edit it will take you to the controller. You can get the third url parameter direct in as show in the controler code:
You can also use get as shon
Your Controller should be:
public function edit_student($id){
$student_data = $this->student_model->get_student_data($id);
$this->load->view('your_view',['student_data'=>$student_data)]);
}
Here is you model which get the id form controllr and find the student data and passit to back to the controller:
Your Model should be:
public function get_student_data($id){
$this->db->select('*');
$this->db->from('your_table_name');
$this->db->where('id',$id);
$query = $this->db->get();
$student_data = $query->$row_array();
if(isset($student_data) && !empty($student_data)){
return student_data;
} else {
return FALSE;
}
}
Form controller you pass the data to the view.
On View Side:
<?php
// Just to ensure the data. Comment it after testing
echo "<pre>";
print_r($student_data);
echo "</pre>";
?>
<form action="<?= base_url('student/update_student') ?>/<?= $student_data['id'] ?>">
<input name="your_column_name" value="<?= $student_data['your_column_name'] ?>">
// Try to do the same for all you column.
<input type="submit" value="updata">
</form>
Here is the controller for update the data
public function update_student($id){
$student_data = $this->input->post();
$status = $this->student_model->update_student($id,$student_data);
if($status == TRUE){
$this->load->view('your_view');
// Your Success view
} else {
// Your view if fail to update
$this->load->view('your_view');
}
}
Here is the model for update the data
public function get_student_data($id,$student_data){
$this->db->where('id',$id);
$this->db->update('your_table_name',$student_data);
if($this->db->affected_rows() == 1){
return TRUE;
} else {
return FALSE;
}
}
Very similar to what you have done for delete. Something like this:
<td>
<a href="" >Edit/Delete</a>
<!-- This should be another method in Student controller -->
<i class="icon-trash"><!-- I changed order of edit and delete -->
</td>
I need to warn you for CSRF. If you don't implement better security here, anyone pointing to that link would be able to edit or delete data.
Check Security class in documentation and how to set hidden value so that way you would ensure that only one who has already requested that page was able to edit/delete rows.
<td><a href="<?php echo base_url();?>controller_name/function_name/<?php echo $edit_id;?>" >Edit</a></td>
another way
<td><a href="<?php echo base_url();?>controller_name/function_name?id=<?php echo $edit_id;?>" >Edit</a></td>
You can use any one according to your requirement.

Array gets emptied when i try to add new stuff to it (PHP)

I am trying to add stuff into an array after every click a user makes on a category but for some reason it keeps replacing everything in the array. I can't figure out where I am going wrong. I've tried 'googling' it and every example i find looks similar to what i have written. Please Help!
these functions are store in core.php
function getStoreBacktrace($cat) {
include("config.php");
$backtrace = array();
if ($cat != 0) {
array_push($backtrace, $cat);
}
if (count($backtrace != 0)) {
foreach($backtrace as $c){
echo getBackCatName($c);
}
}
print_r($backtrace); // Put this to see what output is
}
function getBackCatName($c) {
include("config.php");
$query = 'SELECT * FROM `home_store_cats` WHERE `id`="'.$c.'"';
$r_query = mysql_query($query);
$result = mysql_fetch_array($r_query);
echo ' > '.$result['name'].'';
}
this function prints out a list of links the user can click on
function getStoreCat($cat) {
include("config.php");
$query = 'SELECT * FROM `home_store_cats` WHERE `main`="'.$cat.'" ORDER BY `name` ASC';
$r_query = mysql_query($query);
echo '<ul>';
while ($result = mysql_fetch_array($r_query)) {
echo '<li>';
echo ''.$result['name'].'';
echo '</li>';
}
echo '</ul>';
}
and it gets called in store.php
<?php
include("config.php");
include("core.php");
$backtrace = array();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title><?php echo getSiteTitle().' :: '.getSiteSlogan(); ?></title>
</head>
<body>
<table width="100%">
<tr>
<td colspan="2">
<!-- Backtrace -->
Home
<?php echo getStoreBacktrace($cat, $backtrace); ?>
</td>
</tr>
<tr>
<td>
<!-- Categories -->
<table>
<tr>
<td><?php echo getStoreCat($cat); ?></td>
</tr>
</table>
</td>
<td>
<!-- Products -->
<table>
<tr>
<?php echo getStoreProducts($cat); ?>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
now everytime a user clicks on a link that is made from the function getStoreCat($cat) it refreshes the page with new links to click on and new products to show depending on what $cat they chose. i want to push the $cat to the $backtrace array.
Right here:
$backtrace = array();
You are effectively resetting the array for each call to getStoreBacktrace().
EDIT:
Thanks for fixing your question. Now it's clear that the issue is you need to make $backtrace persistent through multiple page views. Do this using sessions:
Page template
<?php
session_start(); // enable sessions
include("config.php");
include("core.php");
?>
<!DOCTYPE html>
etc...
Function definition
<?php
function getStoreBacktrace($cat) {
include_once("config.php"); // use include_once() to prevent possible errors
if (!isset($_SESSION['backtrace']))
$_SESSION['backtrace']= array();
if ($cat != 0) {
array_push($_SESSION['backtrace'], $cat);
}
...
Everytime you call getStoreBacktrace you instantiate a brand new array in $backtrace.

CakePHP: Error: The view for TasksController::index() was not found

I use CakePHP 2.5.5 . My project in this directory: C:\xampp\htdocs\vy\cakephp-2.5.5 . My project directory layout:
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\Model\task.php (Model)with content:
<?php
class Task extends AppModel
{
var $name = 'Task';
}
?>
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\Controller\TasksController.php (Controller) with content:
<?php
class TasksController extends AppController
{
var $name = 'Tasks';
function index()
{
$this->set('tasks', $this->Task->find('all'));
}
}
?>
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Task\index.ctp (View) with content:
<h2>Tasks</h2>
<?php if (empty($tasks)): ?>
There are no tasks in this list
<?php else : ?>
<table>
<tr>
<th>Title</th>
<th>Status</th>
<th>Created</th>
<th>Modified</th>
<th>Actions</th>
</tr>
<?php foreach ($tasks as $task): ?>
<tr>
<td>
<?php echo $task['Task']['title'] ?>
</td>
<td>
<?php
if ($task['Task']['done']) echo "Done";
else echo "Pending";
?>
</td>
<td>
<?php echo $task['Task']['created'] ?>
</td>
<td>
<?php if ($task['Task']['modified']) ?>
</td>
<td>
<!-- actions on tasks will be added later -->
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
When run program, error:
Missing View
Error: The view for TasksController::index() was not found.
Error: Confirm you have created the file: C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Tasks\index.ctp
Notice: If you want to customize this error message, create app\View\Errors\missing_view.ctp
How to repair above application? Thank you!
All you have to do is read the error message carefully :)
The view folder should be View\Tasks (plural) instead of View\Task as you currently have.
Also your model file name should be Task.php not task.php. Be carefully of case sensitivity in file names. While things will work on windows if you move files to a linux server you will get errors as it has case sensitive filesystem.

displaying only relevant posts

I have a website that is made in php and mysql.
It is a podcast site which I have created.
The home page has a list of podcasts and once one is clicked it then brings up the episode.php?id= followed by the ID that is listed in mysql for that podcast.
at the bottom of the episodes page I have added a comment box.
and I have it to display the comments saved in mysql using:
<?php class feedback {
public function fetch_all(){
global $pdo;
$query = $pdo->prepare("SELECT * FROM comments");
$query->execute();
return $query->fetchAll();
} }
$feedback = new feedback;
$articles = $feedback->fetch_all();
?>
<html>
<body>
<?php foreach ($articles as $feedback) { ?>
<div class="comment" align="center">Name: <font size="3" color="grey"><?php echo $feedback['name']; ?></font> Email: <font size="3" color="grey">Hidden</font>
<br />
<font size="5" color="red"><div align="left"><?php echo $feedback['post']; ?></font></div></div>
<br><div class="divider2"> </div><br>
<?php } ?>
</html>
</body>
This displays all the comments that are listed in the comments field in mysql.
each comment has a "cast" tab which displays the id of the podcast.
How can I get this to reflect the page being viewed?
for example.
if I'm viewing episode.php?id=1 then I want the comments with the "cast" tab of "1" to be displayed and not the "cast" tab of "2". Also the same goes for episode.php?id=2. and so on!
Please can someone guide me on how to do this?
thank you.
Kev
so I had a little play around with this after trying Timo Dörsching's suggestion which did not work.
I hit undo to get it back to my original post and changed this:
<?php foreach ($articles as $feedback) { ?>
<div class="comment" align="center">Name: <font size="3" color="grey"><?php echo $feedback['name']; ?></font> Email: <font size="3" color="grey">Hidden</font>
<br />
<font size="5" color="red"><div align="left"><?php echo $feedback['post']; ?></font></div></div>
<br><div class="divider2"> </div><br>
<?php } ?>
to this:
<?php foreach ($articles as $feedback) {
if ($feedback['cast'] === $_GET['id']) { ?>
<div class="comment" align="center">Name: <font size="3" color="grey"><?php echo $feedback['name']; ?></font> Email: <font size="3" color="grey">Hidden</font>
<br />
<font size="5" color="red"><div align="left"><?php echo $feedback['post']; ?></font></div></div>
<br><div class="divider2"> </div><br>
<?php } } ?>
this does the job perfectly.
perhaps you have to filter the $_GET['id'] & $cast.... but this easy to google how to do this...
Have a look at: How can I prevent SQL injection in PHP?
$cast = $_GET['id'];
public function fetch_all($cast){
global $pdo;
$query = $pdo->prepare("SELECT * FROM comments WHERE cast/id/... = ".$cast."");
$query->execute();
return $query->fetchAll();
} }
$feedback = new feedback;
$articles = $feedback->fetch_all();

Categories