worldcomingtoanend Posted February 1, 2009 Share Posted February 1, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/ Share on other sites More sharing options...
Snart Posted February 1, 2009 Share Posted February 1, 2009 What data is there in the table and which output are you expecting? Link to comment https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752065 Share on other sites More sharing options...
tivrfoa Posted February 1, 2009 Share Posted February 1, 2009 are you trying this: print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n"); Link to comment https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752067 Share on other sites More sharing options...
worldcomingtoanend Posted February 1, 2009 Author Share Posted February 1, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752159 Share on other sites More sharing options...
worldcomingtoanend Posted February 1, 2009 Author Share Posted February 1, 2009 are you trying this: print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n"); i have tried the above but its not displaying any images. my image path is also correct. Link to comment https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752164 Share on other sites More sharing options...
tivrfoa Posted February 1, 2009 Share Posted February 1, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752165 Share on other sites More sharing options...
worldcomingtoanend Posted February 1, 2009 Author Share Posted February 1, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752167 Share on other sites More sharing options...
tivrfoa Posted February 2, 2009 Share Posted February 2, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-752543 Share on other sites More sharing options...
worldcomingtoanend Posted February 3, 2009 Author Share Posted February 3, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-753405 Share on other sites More sharing options...
tivrfoa Posted February 3, 2009 Share Posted February 3, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-753596 Share on other sites More sharing options...
waynew Posted February 3, 2009 Share Posted February 3, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-753643 Share on other sites More sharing options...
worldcomingtoanend Posted February 4, 2009 Author Share Posted February 4, 2009 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 https://forums.phpfreaks.com/topic/143384-output-images-from-database-problem-help/#findComment-754263 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.