01gbanks Posted December 17, 2010 Share Posted December 17, 2010 Hi everyone, i am just trying to learn php for a bit of fun really and started making a sort of 'facebook' website. I am having trouble however trying to display different users images, for example when trying to find a correct 'friend' only the image of the last result is being shown for all people with the same name... here is my code below, if anyone can help me out that would be great file 1 $count=1; while ($numids>=$count){ echo "<form method=\"post\" action=\"friendadded.php\">"; $frienduserid=$_SESSION["passedid[$ii]"]; $friendfirstname=$_SESSION["passedfirstname[$ff]"]; $friendlastname=$_SESSION["passedlastname[$ll]"]; $_SESSION['friendsuserpicid'] = $frienduserid; echo "<table width=\"700\" height=\"50\" border=\"1\" align=\"center\">"; echo "<tr>"; echo "<th></th>"; echo "<th>First Name</th>"; echo "<th>Last Name</th>"; echo "</tr>"; echo "<tr>"; echo "<td><center>"; echo "<img border=\'0\' src=\"frienduserpic.php\" width=\"80\" height=\"80\" align=\"middle\"/>"; echo "</center></td>"; echo "<td><center>"; echo $friendfirstname; echo "</center></td>"; echo "<td><center>"; echo $friendlastname; echo "</center></td>"; echo "</tr>"; echo "</table>"; echo "<center><input type=\"submit\" value=\"Add this friend\" name=\"Add Friend\"></center><br/>"; $ii=$ii+1; $ff=$ff+1; $ll=$ll+1; $count=$count+1; echo "</form>"; } file 2 session_start(); $passeduserid=$_SESSION['friendsuserpicid']; $timespost=$_SESSION['postednum']; $host= $username= $password= $db_name= $tbl_name= mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $query = mysql_query("SELECT * FROM $tbl_name WHERE picid='".$passeduserid."'"); $row = mysql_fetch_array($query); $content = $row['image']; header("Content-type: image/jpeg"); echo $content; Thanks in advance Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 17, 2010 Share Posted December 17, 2010 i suggest that you do not store images in your database. just store the image name or path. Quote Link to comment Share on other sites More sharing options...
01gbanks Posted December 17, 2010 Author Share Posted December 17, 2010 i suggest that you do not store images in your database. just store the image name or path. Thanks for the reply, i have read quite a few good/bad points for doing this, but as this database isnt going to grow massively and im doing it as a learning exercise i figured it wasnt so bad... do you have any ideas on the problem? Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 17, 2010 Share Posted December 17, 2010 IF you are seeking to access multiple records you need to incoporate a WHILE. ie this $row = mysql_fetch_array($query); will only return 1 record while (no pun intended) while($row= mysql_fetch_array($query)){ echo $row['somefieldname']; } will produce all the records that match your query criteria Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2010 Share Posted December 17, 2010 Your 'file 2' code can only output one image at a time (that is the way images work on web pages.) Quote Link to comment Share on other sites More sharing options...
01gbanks Posted December 19, 2010 Author Share Posted December 19, 2010 thanks for all the help guys, however im still a bit confused... how can i change my file 2 to output more than one image? Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 19, 2010 Share Posted December 19, 2010 Take a look here (it also makes it clearer why people prefer not to store images as blobs) http://www.webdeveloper.com/forum/showthread.php?t=235743 Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 19, 2010 Share Posted December 19, 2010 The URL you put into your <img src="..." alt=""> tag needs to have a GET parameter on the end of the URL that specifies which image your 'file 2' code should output. Your 'file 2' code would use that GET parameter as the picid in the where clause in the query. Quote Link to comment Share on other sites More sharing options...
01gbanks Posted December 22, 2010 Author Share Posted December 22, 2010 The URL you put into your <img src="..." alt=""> tag needs to have a GET parameter on the end of the URL that specifies which image your 'file 2' code should output. Your 'file 2' code would use that GET parameter as the picid in the where clause in the query. how do you mean i need to add a GET parameter? do you mean something like this? <img src=file2.phpGET> because what should come next? and how then do i call the get on the file 2 page? Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 22, 2010 Share Posted December 22, 2010 A GET parameter on a URL looks like - file.php?some_name=value In php you would reference the value using $_GET['some_name'] For what you are doing, you would probably want to use picid as the name. Quote Link to comment Share on other sites More sharing options...
01gbanks Posted December 22, 2010 Author Share Posted December 22, 2010 A GET parameter on a URL looks like - file.php?some_name=value In php you would reference the value using $_GET['some_name'] For what you are doing, you would probably want to use picid as the name. Thank you so much this works brilliantly, you have made my day Quote Link to comment 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.