mssakib Posted August 24, 2011 Share Posted August 24, 2011 Hi I want to display image for my each user. This is my database The uname contains the username of my user and $uname = $_SESSION['user_name'] is my username variable. So i want that when a user named sakib goes to the page it will show only his images. I tried but failed .. need some help. regards SAKIB Link to comment https://forums.phpfreaks.com/topic/245618-displaying-image-from-sql-for-each-user/ Share on other sites More sharing options...
mssakib Posted August 24, 2011 Author Share Posted August 24, 2011 Here is what i tried <?php $con = mysql_connect("localhost","root","rdbhaxor"); // EdIT ThIs - mysql_select_db("reg", $con); $sql = "SELECT link FROM myimg WHERE uname='www.gogole.com'"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); $img = mysql_result($result,1); echo $img; ?> <html> <img src=<?php echo $img; ?> width="104" height="142" /> </html> But it only gives 1 image according to the image ID Link to comment https://forums.phpfreaks.com/topic/245618-displaying-image-from-sql-for-each-user/#findComment-1261544 Share on other sites More sharing options...
The Little Guy Posted August 24, 2011 Share Posted August 24, 2011 <?php $user_id = (int)$_SESSION['user_id']; $sql = mysql_query("select * from myimg where loginid = $user_id"); while($row = mysql_fetch_assoc($sql)){ $image = $row['link']; echo "<img src='$image' />"; } ?> Why are you storing the entire url of a local file? What will you do if the domain name changes, or the image path? You will now have to do some fancy regex to fix it. I feel you should just store the file name. What I usually do is store the file name in one column and the extension in a second column. But I don't recommend storing the whole file path. Link to comment https://forums.phpfreaks.com/topic/245618-displaying-image-from-sql-for-each-user/#findComment-1261553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.