Image problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Image problem!

Post 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
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

try mysql_fetch_array in replace of assoc.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Nope tim. That still fails to work! :(
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply