Jump to content

Output Images from Database - Problem - help


worldcomingtoanend

Recommended Posts

I saved my image path to a database and tried to retrieve the actual images using the code below. 

<?php

  $db = odbc_connect("asaa","asaa_user","asas");

  $sql = "SELECT id, url, time FROM fotogalerie";

  $res = odbc_exec($db, $sql);

  while ($row = odbc_fetch_array($res)) {

    print($row['id'].",".$row['url'].",".$row['time']."\n");

  } 

  odbc_free_result($res);

 

  odbc_close($db);

?>

Instead of getting the images that I need I get the output below:

101,/gg/en/pple/007_old/bild1.jpg, 102,/gg/en/pple/007_old/image1.jpg,

101,/gg/en/pple/007_old/bild1.jpg, 102,/gg/en/pple/007_old/image2.jpg,

101,/gg/en/pple/007_old/bild1.jpg, 102,/gg/en/pple/007_old/image3.jpg,

 

where am I going wrong?  Thanky for your help

Link to comment
Share on other sites

What data is there in the table and which output are you expecting?

sorry for delaying was in a meeting.  Ok the database has an image path.  I understand that it is less burdensome for a database to hv image paths instead of  actual images which tends to slow down the database.  so i understand if u store image paths in the databases u can then output the image by retrieving the image path.

 

Link to comment
Share on other sites

are you trying this:

 

print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

  my image path is also correct.

 

are you sure? are you including this page in other page? try to use absolute path!

 

show us the absolute path of the script

Link to comment
Share on other sites

are you trying this:

 

print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

  my image path is also correct.

 

are you sure? are you including this page in other page? try to use absolute path!

 

show us the absolute path of the script

 

in fact I saved the image path to the database in this format:  /gg/en/pple/007_old/image1.jpg

Link to comment
Share on other sites

Remove the first slash:

 

use this: gg/en/pple/007_old/bild1.jpg

instead of: /gg/en/pple/007_old/bild1.jpg

 

eg:

 

<?php

// script path:  http://localhost/your_script.php
// image path: http://localhost/gg/en/pple/007_old/bild1.jpg

$imgPath1 = 'gg/en/pple/007_old/bild1.jpg'; // this works
$imgPath2 = '/gg/en/pple/007_old/bild1.jpg'; // this won't work

$img1 = "<img src='$imgPath1' />";
$img2 = "<img src='$imgPath2' />";

echo $img1;
echo '<br />';
echo $img2;
?>
<html>
<?php echo $img1; ?><br />
<?php echo $img2; ?>
<body>
<?php echo $img1; ?><br />
<?php echo $img2; ?>
</body>
</html>

Link to comment
Share on other sites

 

thanks tivrfoa. i hv tried all that but for some reason it outputs triangles only and not the actual images. I have also double checked my path, my image location, absolute path etc and all is okay.  ok maybe let me give the full code once more:

<?php
  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);

while ($row = odbc_fetch_array($res)) {
  print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

   }  
  
odbc_free_result($res);

odbc_close($db);
?>

the above code displays everything else except for the images. i hv tried all I can but dont know where the problem is. 

Link to comment
Share on other sites

 

thanks tivrfoa. i hv tried all that but for some reason it outputs triangles only and not the actual images. I have also double checked my path, my image location, absolute path etc and all is okay.  ok maybe let me give the full code once more:

<?php
  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);

while ($row = odbc_fetch_array($res)) {
  print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

   }  
  
odbc_free_result($res);

odbc_close($db);
?>

the above code displays everything else except for the images. i hv tried all I can but dont know where the problem is. 

write here the absolute path of your script.php and the images you are using.

 

did you try?

Remove the first slash:

 

use this: gg/en/pple/007_old/bild1.jpg

instead of: /gg/en/pple/007_old/bild1.jpg

 

try this:

<?php

  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);

while ($row = odbc_fetch_array($res)) {
$imgPath = substr($row['url'], 1);
print($row['id'].",<img src='$imgPath'>,".$row['time']."\n");
}  
  
odbc_free_result($res);

odbc_close($db);
?>

Link to comment
Share on other sites

 

thanks tivrfoa. i hv tried all that but for some reason it outputs triangles only and not the actual images. I have also double checked my path, my image location, absolute path etc and all is okay.  ok maybe let me give the full code once more:

<?php
  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);

while ($row = odbc_fetch_array($res)) {
  print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

   }  
  
odbc_free_result($res);

odbc_close($db);
?>

the above code displays everything else except for the images. i hv tried all I can but dont know where the problem is. 

 

Post the resulting html please.

Link to comment
Share on other sites

The actual view page now shows little white boxes with red Xs.  I really dont know where I am going wrong.  Ok now let me give u the 2 codes, a). The one I used to save the image path b) the one i used to try retrieve the image.

 

the first one to save the image path to database:

 

<?php
  $db = odbc_connect("asas","asass","asasa");

$sql = "INSERT INTO foto (id, url) VALUES ("
      . " 101, 'gg/Fotos/bild1.jpg')";
  $res = odbc_exec($db, $sql);
  if (!$res) {
    print("SQL statement failed with error:\n");
    print(odbc_error($db).": ".odbc_errormsg($db)."\n");
  } else {
    print("One data row inserted.\n");
  }  

  $sql = "INSERT INTO foto (id, url) VALUES ("
      . " 102, 'gg/Fotos/bild2.jpg')";
  $res = odbc_exec($db, $sql);
  print("One data row inserted.\n");

odbc_close($db);
?>

 

the code i use to try to retrieve and see my images is as follows:

<?php
  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);

while ($row = odbc_fetch_array($res)) {
  print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");

   }  
  
odbc_free_result($res);

odbc_close($db);
?>

besides the code above I hv tried the rest that have been suggested here but they have not worked.  The first code successfully writes everything to the database but the second code only outputs the ID number and red boxes without my images.

 

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.