i am tying to do this by a function. i want every item found in the db to be echoed out as a list
eg. item1
item2
item3
item4
i know im missing something but it is puzzling me. for now im only seeing one list and upon
refresh another item shows up replacing the other. plz help and thanks
function get_list() {
$id = mysql_real_escape_string(@$_GET['id']);
$get_list = array();
$bar = mysql_query(" SELECT bar.* FROM bar WHERE bar.b_id = '$id' ORDER BY rand()");
while($kpl = mysql_fetch_assoc($bar)){
$get_list[] = array( 'videoid' => $kpl['videoid'],
'name' => $kpl['name'],
'description' => $kpl['description'],
'type' => $kpl['type'],
'bev' => $kpl['bev'],
);
}
foreach ($get_list as $get_list);
return $get_list;
}
?>
<?php
$gkp_list = gkp_list();
foreach ($gkp_list as $gkp_list);
if (empty($gkp_list)){ echo 'no video'; }
else {
echo '<p>$gkp_list['name']. '<br/></p>';}
?>
There are some major syntax problems there.
foreachis to loop over an array and do something with each value. Don’t use foreach if you’re working with the array as a whole (in this case, returning it){).whileloop, because all of the indexes are the same.foreachmust be different. One refers to the array, and one refers to the value of that key.