Displaying images

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
leewad
Forum Commoner
Posts: 91
Joined: Tue May 11, 2004 8:32 am

Displaying images

Post by leewad »

Hi

I`m trying to pull from a database a list of images for a reference number, i.e.

reference acbd has 6 images stored

image1
image2
image3
image4
etc

how can i pull these from the database and use them?

I have created this to pull them:

Code: Select all

$result1=MYSQL_QUERY( "SELECT * FROM $table WHERE reference  ='$ID' ");

if(mysql_num_rows($result1)) {

   while($row = mysql_fetch_row($result1))
  {

    $picture[$i] = $row["1"];


  $i++;


  } }

$image1 = $picture[1];
$image2= $picture[2];
etc

but its not working, any ideas to where i`m going wrong?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Not knowing your database structure or anything...
Two things leap out at me:

Code: Select all

$result1=MYSQL_QUERY( "SELECT * FROM $table WHERE reference  ='$ID' ");
The function isn't going to be recognized in capitals, and the spaces in the query string might or might not be problematic.
Try:

Code: Select all

$result1=mysql_query( "SELECT * FROM $table WHERE reference='$ID'");
The other:

Code: Select all

$image1 = $picture[1];
$image2= $picture[2];
Arrays in PHP start at zero. The $picture indices should be 0 and 1.

These suggestions may or may not solve the problem, but they are a start. If they don't then if you'll provide more about the structure of your database we'll give it another shot.
Post Reply