Kay009 Posted November 6, 2009 Share Posted November 6, 2009 i have worked my way through storing images in directory and storing the location in mySQL db.Now i was trying to make a Image gallery for just that particular user who had uploaded those images. i am having problem with that. <?php session_start(); $username = $_SESSION['UserName'] ; echo "Username : ".$username."<br/><br/>"; $user=$username;//storing session in another variable include('dbconnect.php');//Conncetion to Database $qry = "SELECT * FROM UserImage WHERE UserName = '$user' "; $result = mysql_query($qry,$connection); $result2 = mysql_num_rows($result); if($result2 == 0) {die('Username does not exist.');} else{ [b]/////I need help here.how do i make all those images display here[/b] } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180545-displaying-pictures/ Share on other sites More sharing options...
cags Posted November 6, 2009 Share Posted November 6, 2009 So you successfully have the file uploading and that code successfully fetches the path to the image from your database?! while($row = mysql_fetch_assoc($result)) { echo '<img src="' . $row['name_of_path_column_here'] .'" />'; } Quote Link to comment https://forums.phpfreaks.com/topic/180545-displaying-pictures/#findComment-952503 Share on other sites More sharing options...
Kay009 Posted November 6, 2009 Author Share Posted November 6, 2009 aww thanks pal. its working as i wanted it to by putting in the while loop=D. Quote Link to comment https://forums.phpfreaks.com/topic/180545-displaying-pictures/#findComment-952511 Share on other sites More sharing options...
Zane Posted November 6, 2009 Share Posted November 6, 2009 I'll start from here $result = mysql_query($qry,$connection); This is your data.. you may not be able to echo $result with it without and error, but it is your data. It's more commonly referred to as a resource. As in MySQL resource. You see to have this part down... pretty straight forward $result2 = mysql_num_rows($result); if($result2 == 0) { die('Username does not exist.'); }else{ /////Display the data in an image gallery. } The displaying your data part consists of taking the RESOURCE and putting it into something that you CAN echo. Like an Array... of Strings (text,letters,numbers) Thankfully PHP has just the function to do that which is called mysql_fetch_array. All you have to feed it is a mysql resource an it spits out an array. mysql_fetch_array($result); But we still can't echo that because... well, what would we echo... unless we just prepended it echo mysql_fetch_array($result); It needs to be stored to a variable. Why not call it $row, since that is what is going to be in this variable.. the top row's data. Until you call mysql_fetch_array again, then it will call the second row. and so on and so on... $result = mysql_query($qry,$connection); $row = mysql_fetch_array($result); echo $row['UserName']; // Prints the first user $row = mysql_fetch_array($result); echo $row['UserName']; // Prints the second user That kind of coding could get to be quite the eyesore afterwhile though and is really illogical.. considering there's loops to take advantage of. $result = mysql_query($qry,$connection); while($row = mysql_fetch_array($result)) { echo $row['UserName']; } That would do the exact same thing. Isn't that neater? Everything beyond that is pretty much basic HTML and CSS. Quote Link to comment https://forums.phpfreaks.com/topic/180545-displaying-pictures/#findComment-952517 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.