Jump to content

[resolved] pictures from database


ksb24930

Recommended Posts

sorry- this is the script I have been working with:

$sql    = "SELECT * FROM imageb";
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
  $row = @mysql_fetch_array ($result);
  $image_type = $row["image_type"];
  $image = $row["image"];
  Header ("Content-type: $image_type");
  print $image;
}

I know this script won't produce more than one image- it is the script I have been tweaking, though.
You need (2) scripts, (1), the script that dumps a image to the browser, and (2) the html script that creates the <img> tags that points to script (1). script (1) reads a single db row based on the id passed to it. script (2) loops all the db rows creating all the <img> tags that will be displayed on the html page -> (script 2)


Sonia
excellent, thank you. Now I think I have those two scripts jumbled in my code pages, but I am unclear about how to call all the pictures- I can pass one picture id through the url, but I don't know how to display all of the images. So, what would an example of the looping script look like?

thanks
Well, the script to show the images would look very simular to the one your posted. Call it showimages.php.

[code]
<?php
$sql    = "SELECT image FROM imageb WHERE id = {$_GET['id']}";
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
  $row = @mysql_fetch_array ($result);
  $image_type = $row["image_type"];
  $image = $row["image"];
  Header ("Content-type: $image_type");
  print $image;
}
?>
[/code]

Now, just as an example script to loop through images 1 - 10.

[code]
<?php
  for ($i = 1; $i < 11; $i++) {
    echo "<img src='showimages.php?id=$i'>";
  }
?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.