Thursday 15 May 2014

php - Cant display an image where image path is stored in a Database -



php - Cant display an image where image path is stored in a Database -

i trying display images on webpage, image path stored in database , images stored in server.but not able display images using next codes, pls help me issue,..

<form method="post" enctype="multipart/form-data" action="file_upload.php"> <table> <?php $dbhost = 'xxxxxxxx'; $dbuser = 'xxxxxxxxx'; $dbpass = 'xxxxxxxxxx'; $db_name = 'xxxxxxxxxx'; $tbl_name = 'xxxxxxxxxxx'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('could not connect: ' . mysql_error()); } mysql_select_db("$db_name")or die("cannot select db"); $query1 = mysql_query("select * '$tbl_name' id='1'"); $rows1 = mysql_fetch_array($query1); $path1 = $rows1['image']; $query2 = mysql_query("select * '$tbl_name' id='2'"); $rows2 = mysql_fetch_array($query2); $path2 = $rows2['image']; $query3 = mysql_query("select * '$tbl_name' id='3'"); $rows3 = mysql_fetch_array($query3); $path3 = $rows3['image']; echo '<tr><td><img src="$path1"></td>' ; echo '<td><img src="$path2"></td>' ; echo '<td><img src="$path3"></td></tr>' ; ?> </form> </table>

take à code :

$b = "aaaaaaa"; echo '"$b"'; // displayt "$b" echo "'$b'"; // displayt 'aaaaaaa' echo "\"$b\"";// displayt "aaaaaaa" come in code here

so, problem it's because if want variable evaluated in string must set between "" , not ''.

class="snippet-code-html lang-html prettyprint-override"><table> <?php $path1 = "/upload/image1.png"; $path2 = "/upload/image2.png"; $path3 = "/upload/image3.png"; echo "<tr><td><img src='$path1'></td>" ; echo "<td><img src='$path2'></td>" ; echo "<td><img src='$path3'></td></tr>" ; ?> </table>

or

class="snippet-code-html lang-html prettyprint-override"><table> <?php $path1 = "/upload/image1.png"; $path2 = "/upload/image2.png"; $path3 = "/upload/image3.png"; echo '<tr><td><img src="'.$path1.'"></td>' ; echo '<td><img src="'.$path2.'"></td>' ; echo '<td><img src="'.$path3.'"></td></tr>' ; ?> </table>

anas

php html mysql sql database

No comments:

Post a Comment