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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.