Problem with $row
Posted: Thu Sep 30, 2010 7:22 am
This is a little tricky to explain but I'll do my best.
For reasons that I won't go into right now (for fear of boring you all to death) I have written the following code which interrogates a table named "photos" and uses a filename to call a second PHP page.
Here's the clincher. The $scode array has multiple instances through the table.
What I WANT the code to do is find the first instance of $scode (i.e. the first row where code = $scode) and use THAT filename. As it stand the code works fine but it sets $filename as the LAST instance of $scode that matches.
Am I making any sense whatsoever?!
For reasons that I won't go into right now (for fear of boring you all to death) I have written the following code which interrogates a table named "photos" and uses a filename to call a second PHP page.
Code: Select all
$query = "SELECT * FROM photos WHERE code='$scode'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
if (mysql_num_rows($result) == 0)
{echo "<tr><td class='photolink' $al colspan='2'> </td></tr>";}
else
{
while($row = mysql_fetch_assoc($result))
$filename = $row['filename'];
echo "<tr><td class='photolink' $al colspan='2'><a href='gallery.php?category=$catsel&scode=$scode&autostart=$filename'><img src='../graphics/services/gallery.gif' title='Click here to view our $service image gallery!' alt=''></img></a></td></tr>";}What I WANT the code to do is find the first instance of $scode (i.e. the first row where code = $scode) and use THAT filename. As it stand the code works fine but it sets $filename as the LAST instance of $scode that matches.
Am I making any sense whatsoever?!