thewooleymammoth Posted March 16, 2009 Share Posted March 16, 2009 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' Link to comment https://forums.phpfreaks.com/topic/149697-solved-loop-through-each-row-for-a-result/ Share on other sites More sharing options...
rhodesa Posted March 16, 2009 Share Posted March 16, 2009 $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 Link to comment https://forums.phpfreaks.com/topic/149697-solved-loop-through-each-row-for-a-result/#findComment-786095 Share on other sites More sharing options...
thewooleymammoth Posted March 16, 2009 Author Share Posted March 16, 2009 $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? Link to comment https://forums.phpfreaks.com/topic/149697-solved-loop-through-each-row-for-a-result/#findComment-786099 Share on other sites More sharing options...
rhodesa Posted March 16, 2009 Share Posted March 16, 2009 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. Link to comment https://forums.phpfreaks.com/topic/149697-solved-loop-through-each-row-for-a-result/#findComment-786103 Share on other sites More sharing options...
thewooleymammoth Posted March 16, 2009 Author Share Posted March 16, 2009 sweet i guess i just didnt really know what that ment. aprreciate the help Link to comment https://forums.phpfreaks.com/topic/149697-solved-loop-through-each-row-for-a-result/#findComment-786107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.