Jump to content

Recommended Posts

Ive been searching for a way to do this but there is so many results for these key words i cant find anything so sorry if this has already been answered.

 

what im trying to do is essentually setup a mail inbox. i have a database setup with a reciver field a subject field and a date field(and some other irrelevant fields). and what i need to do is query for all rows with the recipient being the user loop through each row returned to display each message for that user. I cant seem to figure out how to do that. mysql_fetch array and mysql_fetch_assoc only return one row.

 

here is my mysql query

 

SELECT *
FROM `dev_messages` 
WHERE `reciever` = '$uname'

$sql = "SELECT * FROM `dev_messages` WHERE `reciever` = '$uname'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
 print_r($row);
}

 

edit: replace the print_r() part with whatever print statements you want for each entry

$sql = "SELECT * FROM `dev_messages` WHERE `reciever` = '$uname'";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)){
  print_r($row);
}

 

edit: replace the print_r() part with whatever print statements you want for each entry

 

so each time you fetch array it gives you the next result?

yes

 

http://us3.php.net/mysql_fetch_array

Description

array mysql_fetch_array ( resource $result [, int $result_type= MYSQL_BOTH ] )

 

Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.

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.