Jump to content

Displaying the same blob image


01gbanks

Recommended Posts

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

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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  :D this works brilliantly, you have made my day  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.