Page 1 of 1

Image problem!

Posted: Sun Jul 04, 2004 4:50 pm
by Joe
I am having a bit of problem with my database images. I posted a couple of days ago to see how I can get a row of 6 images if anyone remembers. Anyway the problem now is that its not showing the ID for the links. The code go's like:

Code: Select all

while (true)
{
 $row = mysql_fetch_assoc($result);
 if ($row == false) break;
 $images[] = $row['image'];
 $ID = $row['ID'];
}

for($x = 0, $y = count($images); $x < $y; $x++)
{
  if($x % 6 == 0)
  echo '<tr>';

  echo '<td><A href="viewtopic.php?ID="'.$ID.'"><img src="'.$images[$x].'" border=0 /></A></td>&nbsp;&nbsp;';

  if($x % 6 == 5)
  echo '</tr>';
}

$y = ($y + 5) % 6;

if($y != 5)
echo '<td colspan=".($y+1)."> </td></tr>';
You can see the line where I try to show the ID:
echo '<td><A href="viewtopic.php?ID="'.$ID.'"><img src="'.$images[$x].'" border=0 /></A></td>&nbsp;&nbsp;';
Any help appreciated.

Regards


Joe

Posted: Sun Jul 04, 2004 4:53 pm
by tim
try mysql_fetch_array in replace of assoc.

Posted: Sun Jul 04, 2004 4:59 pm
by Joe
Nope tim. That still fails to work! :(

Posted: Sun Jul 04, 2004 5:17 pm
by redmonkey
When MySQL returns a associative array it is case sensitive, e.g. if you created the table column as 'ID' it will return 'ID' whereas if the column was created as 'id' then it will be returned as 'id'.

Also, you are assigning a value to $ID each time you call a result row. Which means when you exit the while loop $ID will only have the value of the last result row. You need to declare $ID as an array.

You should try increasing your error level reporting to report 'notices' it will help to give you some hints as to where the problem may be.

Posted: Mon Jul 05, 2004 12:24 am
by feyd
try

Code: Select all

<?php

while (true) 
{ 
$row = mysql_fetch_assoc($result); 
if ($row == false) break; 
$images[] = $row['image']; 
$ID[] = $row['ID']; 
} 

for($x = 0, $y = count($images); $x < $y; $x++) 
{ 
  if($x % 6 == 0) 
  echo '<tr>'; 

  echo '<td><A href="viewtopic.php?ID="'.$ID[$x].'"><img src="'.$images[$x].'" border=0 /></A></td>  '; 

  if($x % 6 == 5) 
  echo '</tr>'; 
} 

$y = ($y + 5) % 6; 

if($y != 5) 
echo '<td colspan=".($y+1)."> </td></tr>'; 

?>
Assuming the field name is in fact ID, as redmonkey talked about..