jalaladdin Posted October 23, 2011 Share Posted October 23, 2011 i wrote this code for dispaly image but IE don't show it <?php// connect to mysql server$link = mysql_connect('localhost', 'root', '');if (!$link) { die('Not connected : ' . mysql_error());}// connect to database server$db_selected = mysql_select_db('admin', $link); if (!$db_selected) { die ('Database error : ' . mysql_error());} $sql = mysql_query("SELECT 'path' FROM image WHERE id='3' "); while($row= mysql_fetch_array($sql)){ $image = $row['path']; // $image = $row['path']; echo'<img src="$image"/>';}?> Link to comment Share on other sites More sharing options...
jalaladdin Posted October 23, 2011 Author Share Posted October 23, 2011 please help me Link to comment Share on other sites More sharing options...
Don E Posted October 23, 2011 Share Posted October 23, 2011 For 'path', is the whole path to the image stored there or is it just the image name? In other words, does $image turn out to equal "me.jpg" or "images/me.jpg"? If it's just "me.jpg" then you have to specify the path to the image for the img src tag: echo '<img src="images/' . $image . ' " />'; Also, from my understanding.. when you query something from the database and it's a number(integer), like id='3', you don't need the single quotes. You can just do id=3. Link to comment Share on other sites More sharing options...
boen_robot Posted October 23, 2011 Share Posted October 23, 2011 $sql = mysql_query("SELECT 'path' FROM image WHERE id='3' "); You should be getting the string "path", and your resulting code should be <img src="path"/> This would work if you have an image named "path" in the same folder as the PHP file, but that's not what you want I assume. To get the value of a column named "path", you need to use ` (backticks) instead of ' (apostrophes), or omit any `. In addition to that, when using numbers, you must omit the apostrophes. Assuming the "id" column is an integer, a more appropriate query would look like: $sql = mysql_query("SELECT path FROM image WHERE id=3"); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.