This is my code for index.php
. I know I can't use foreach
outside class. I don't know what to use instead, there might be something else missing too. I get the error
Using $this when not in object context
I have a SQL table gallery with 6 attributes: name
, thumb
, display
, original
, title
and description
.
I want to list all rows, how am I going to do this if I can't use foreach
outside class in PHP5?
<?php
while (($row = mysql_fetch_object($res)) !== false) {
$data['name'] = $row->name;
$data['thumb'] = $row->thumb;
$data['display'] = $row->display;
$data['original']= $row->original;
$data['title']= $row->title;
$data['description']= $row->description;
foreach ($this->data as $row){
print "{$row['name']} some HTML {$row['thumb']} some HTML {$row['display']} {$row['original']} some HTML {$row['title']} some HTML {$row['description']} ";
}
?>
I now have this
if (($row = mysql_fetch_assoc($res)) == false) exit;
while (($row = mysql_fetch_assoc($res)) !== false) {
$data['name'] = $row->name;
$data['thumb'] = $row->thumb;
$data['display'] = $row->display;
$data['original']= $row->original;
$data['title']= $row->title;
$data['description']= $row->description;
}
foreach ($data as $row) { print "t {$row['title']}"; }
what I get is 't t t t t t' as if I have 6 empty records (Note that I have 6 attributes so its taking the attributes as rows?)