suttercain Posted March 1, 2007 Share Posted March 1, 2007 Quick Question: Echo An Image From MySQL, I got it but... I need to add tb_ in front of the 'image.jpg' so it'll actually echo 'tb_image.jpg' CODE echo "<td><img src=$row[cover]></td>"; I tried: echo "<td><img src=$rowtb_[cover]></td>"; But of course it didn't work... Any suggestions? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/ Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 try echo "<td><img src=tb_$row[cover]></td>"; or for testing $X = "tb_".$row[cover]; <td><img src=$X></td>; Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196510 Share on other sites More sharing options...
suttercain Posted March 1, 2007 Author Share Posted March 1, 2007 Hey MadTechie, Thanks for the reply. I tried both but neither worked out for me: echo "<td><img src=tb_$row[cover]></td>"; resulted in the following image path: http://localhost/Superman/tb_images/520027.jpg (Should be http://localhost/Superman/images/tb_520027.jpg to work) And the other code: $X = "tb_".$row[cover]; <td><img src=$X></td>; resulted in the following image path: http://localhost/Superman/tb_ I know, I have tried different ways but so far no luck. Any other suggestions? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196517 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 OK the reason for that is because $row[cover] = "images/520027.jpg" so try this <?php $X = split("/",$row[cover]); echo "<td><img src=".$X[0]."tb_".$X[1]."></td>"; ?> if this fails can you also post the results of a <?php print_r($row[cover]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196526 Share on other sites More sharing options...
suttercain Posted March 1, 2007 Author Share Posted March 1, 2007 Thanks Mad Techie, I tried both of those but neither seems to work. The first still lead to: http://localhost/Superman/tb_ And the print_r function echoed the root directory of the image within the table. Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196536 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 ok not sure why that didn't work can you post the results of this <?php print_r($row); echo "---<br>" $X = split("/",$row[cover]); print_r($X); echo "$X[0]tb_$X[1]"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196545 Share on other sites More sharing options...
suttercain Posted March 1, 2007 Author Share Posted March 1, 2007 Hi MadTechie, Should the code be included in the while loop: Here is my entire code: <?php #specify the connection information $db_server ="localhost"; $db_name = "comics"; $username = "root"; $password = NULL; # #The following lines do not need to be edited # #make the connection. If there is a problem, print out a helpful error message $dbh = @mysql_connect($db_server,$username,$password) or die ("Connection to $db_server with login '$username'/'$password' failed."); if ($dbh = TRUE) { echo "Connected!"; } #select the database. If the database is not found on the server, let us know $db = @mysql_select_db($db_name) or die ("Connection made. But database '$db_name' was not found."); // Begin your table outside of the array echo "<table width='100%' border='0' cellpadding='1' cellspacing='0'> <tr> <td width='110'><b></b></td> </tr> <tr> <td width='110'><b></b></td> <td width='110'><b>WRITERS</b></td> <td width='110'><b>PUBLISHED</b></td> </tr>"; // Perform an statndard SQL query: $res = mysql_query("SELECT cover, title, email, publish_date FROM comics ORDER BY title ASC") or die (mysql_error()); // Assuming $res holds the results from your query: $class = 'even'; while ($row = mysql_fetch_assoc($res)) { $class = $class == 'even' ? 'odd' : 'even'; echo "<tr class=\"$class\">\n"; echo "<td><img src=$row[cover]></td>"; <---IMAGE BEING ECHOED echo "</tr>\n"; echo "<tr class=\"$class\">\n"; echo "<td>$row[title]</td>\n"; echo "<td>$row[email]</td>\n"; echo "<td>$row[publish_date]</td>\n"; echo "</tr>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196566 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 Ahh ha try this <?php #specify the connection information $db_server ="localhost"; $db_name = "comics"; $username = "root"; $password = NULL; # #The following lines do not need to be edited # #make the connection. If there is a problem, print out a helpful error message $dbh = @mysql_connect($db_server,$username,$password) or die ("Connection to $db_server with login '$username'/'$password' failed."); if ($dbh = TRUE) { echo "Connected!"; } #select the database. If the database is not found on the server, let us know $db = @mysql_select_db($db_name) or die ("Connection made. But database '$db_name' was not found."); // Begin your table outside of the array echo "<table width='100%' border='0' cellpadding='1' cellspacing='0'> <tr> <td width='110'><b></b></td> </tr> <tr> <td width='110'><b></b></td> <td width='110'><b>WRITERS</b></td> <td width='110'><b>PUBLISHED</b></td> </tr>"; // Perform an statndard SQL query: $res = mysql_query("SELECT cover, title, email, publish_date FROM comics ORDER BY title ASC") or die (mysql_error()); // Assuming $res holds the results from your query: $class = 'even'; while ($row = mysql_fetch_assoc($res)) { $class = $class == 'even' ? 'odd' : 'even'; echo "<tr class=\"$class\">\n"; //echo "<td><img src=$row[cover]></td>"; #<---IMAGE BEING ECHOED $X = split("/",$row['cover']); #<----NEW!! echo "<td><img src=".$X[0]."tb_".$X[1]."></td>"; #<----NEW!! echo "</tr>\n"; echo "<tr class=\"$class\">\n"; echo "<td>$row[title]</td>\n"; echo "<td>$row</td>\n"; echo "<td>$row[publish_date]</td>\n"; echo "</tr>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196585 Share on other sites More sharing options...
suttercain Posted March 1, 2007 Author Share Posted March 1, 2007 Awesome, that worked great! Thank you so much for your time. Shannon Quote Link to comment https://forums.phpfreaks.com/topic/40632-solved-quick-question-echo-an-image-from-mysql-i-got-it-but/#findComment-196588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.