The user specifies the fields to pull from the database, they are listed in the query with commas. Then I turn them into an array and remove the commas and in a foreach loop put a $ in front of them. All that works.
The problem is, the next step is to put a value to the variable using list(). I would love to implode the array there [list(implode(',',$array))=mysql_fetch_array...] but that doesn't work.
Can anyone help me get the variables in list(), in the below case the solution is: list($id,$image,$title)
Thank you in advance!
Code: Select all
class Pgrid{
var $grid_fields;
var $grid_table;
var $grid_order;
var $grid_thumb_url;
var $grid_row="5";
function pgrid_grid(){
$query="SELECT $this->grid_fields FROM $this->grid_table ORDER BY $this->grid_order ASC";
$result=mysql_query($query) or die (mysql_error());
//Take out comma
$grid_field_array=explode(',',$this->grid_fields);
//Add $ infront of field names
foreach($grid_field_array as &$grid_field_value){
$grid_field_value="$".$grid_field_value;
}
//Test, returns $id, $image, $title <-Perfect
/* foreach($grid_field_array as $value){
echo $value;
}
*/
//Problem area
while(list($this->newvars)=mysql_fetch_array($result)){
echo $this->grid_thumb_url;
//Create rows
++$i;
if($i >= $this->grid_row){
echo "<br />";
// Reset counter
$i=0;
}
}
}
}
Code: Select all
$grid=& new Pgrid();
$grid->grid_fields="id,title,image";
$grid->grid_table="work";
$grid->grid_order="id";
$grid->grid_url='<a href="work-$id.html"><img src="images/portfolio/$image_t.jpg" alt="$title" width="80" height="80" /></a>';
echo $grid->pgrid_grid();