Jump to content

Rerieve Image path from database problem -- pliz help am now depressed.


worldcomingtoanend

Recommended Posts

I am trying to output my image path that i have saved to the database.  i need the output to be my literal images.  The output I am getting is table of ID numbers which is fine but instead of images next to the ID numbers I get broken image triangles with exclamation marks.  I have tried to double check my image path, absolute paths, etc but nothing is working.  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);
?>

The first code successfully writes everything to the database but the second code only outputs the ID number and red boxes without my images.

Try

 

echo $row['id'].'<img src="'.$row['url'].'" />'.$row['time']."\n";

the output i get is as below

101101 >102102 >101101 <102102 >101101 <102102 <101101 <102102 <101101 <102102 

the flex brackets that i have put are actually triangles that r out put.

 

Strangely the actual HTML output i get after clicking on view source is as below. It seems strange:

 

<span class="content">
    	101,<img src='gg/Fotos/bild1.jpg'>,
102,<img src='gg/Fotos/bild2.jpg'>,
101,<img src='gg/Fotos/bild1.jpg'>,
102,<img src='gg/Fotos/bild2.jpg'>,
101,<img src='gg/Fotos/bild1.jpg'>,
102,<img src='gg/Fotos/bild2.jpg'>,
101,<img src='gg/Fotos/bild1.jpg'>,
102,<img src='gg/Fotos/bild2.jpg'>,
101,<img src='gg/Fotos/bild1.jpg'>,
102,<img src='gg/Fotos/bild2.jpg'>,
101,<img src='www.sasass.com/picos/take/one.jpg'>,
102,<img src='www.sasass.com/picos/take/two.jpg'>,
101,<img src='www.sasass.com/picos/take/one.jpg'>,
102,<img src='www.sasass.com/picos/take/two.jpg'>,
101,<img src=''g/Fotos/bild2.jpg'>,
102,<img src='g/Fotos/bild2.jpg'>,
101,<img src=''g/Fotos/bild2.jpg'>,
102,<img src='g/Fotos/bild2.jpg'>,
101,<img src=''g/Fotos/bild2.jpg'>,
102,<img src='g/Fotos/bild2.jpg'>,
101,<img src=''g/Fotos/bild2.jpg'>,
102,<img src='g/Fotos/bild2.jpg'>,
101,<img src=''g/Fotos/bild2.jpg'>,
102,<img src='g/Fotos/bild2.jpg'>,

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

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

odbc_close($db);
?>

 

Please try this code, if it works do let me know.

 

Cheers

i tried the code above and  I get the same output as before but this time if I hover on the triangles it displays my image path and if I click on the triangles it displays the code below:

<?php echo $row['url'];?>

<?php

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

  $sql = "SELECT id, url FROM foto";

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

 

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

?>

<img src="<?php echo $row['url'];?>">

  <?php

  } 

 

odbc_free_result($res);

 

odbc_close($db);

?>

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.