Forum Moderators: coopster
$query = "select * from images where id='$id'";
$result = mysql_query($query);
while($row=mysql_fetch_array($result))
{
$image = $row['image_filename'];
}
When I use the code below, only the last image displays. I want to select which one to display, for example the first or second one.
print "<img src='$image'>";
$query = "select * from images where id='$id'";
$result = mysql_query($query);
$k=0;
while($row=mysql_fetch_array($result))
{
$image[$k] = $row['image_filename'];
}
$selected_image = "2"; //second image
echo "<img src=$image[$selected_image] border=0>";
this should work:
$query = "SELECT image_filename FROM images WHERE id='$id'";
$result = mysql_query($query);while($row=mysql_fetch_assoc($result))
{
$image[] = $row['image_filename'];
}
$selected_image = 2; //second image
echo "<img src=". $image[$selected_image] ." border=0>";//you can't have an array in quotes, you need "bla {$a['1']}"; or better to use '.': "bla ". $a['1'] ."etc..."
Best regards
Michal Cibor
mysql_fetch_row will return an array unassociated: array('bla1','bla2','bla3')
mysql_fetch_assoc will return an array associated: array('key1'=>'bla1','key2'=>'bla2','key3'=>'bla3')
mysql_fetch_array will return both above array: array('bla1','key1'=>'bla1','bla2','key2'=>'bla2','bla3','key3'=>'bla3')
mysql_fetch_object will return object
It has nothing to do with the solution, and it doesn't matter if id is unique or not (in this case mrnoisy suggested it is not unique)
Best regards
Michal Cibor