Jump to content

returning messages


droidus

Recommended Posts

i am having issues returning all sent messages.  it will only return one for some reason.

 

//If there are sent messages, display them
if ($row = mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result) or die(mysql_error());

    //Open table and create headers
    echo "<table border=\"1\">\n";
    echo "  <tr>\n";
echo "    <th>Recipient</th>\n";
    echo "    <th>Subject</th>\n";
    echo "  </tr>\n";

while(mysql_fetch_array($result))
{
	//Show messages
	$userIDTo = $row['userIDTo']; // Get the recipient's ID number
	$recipient = checkRecipient($userIDTo); // Get the sender's Username
	$messageID = $row['ID'];
        echo "  <tr>\n";
	echo "    <td>{$recipient}</td>\n";
        echo "    <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n";
        echo "  <tr>\n";
}

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/247741-returning-messages/
Share on other sites

Are there only 2 messages that would be returned by the query you're currently testing with? You're moving the pointer to the second record before echoing anything by doing this:

 

if ($row = mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result) or die(mysql_error()); // <--- REMOVE THIS LINE

Link to comment
https://forums.phpfreaks.com/topic/247741-returning-messages/#findComment-1272175
Share on other sites

nope :P already tried it.  still returning one.  attached, is what my database looks like.

 

here is my code for the sent messages:

 

<?php
function checkRecipient ($userIDTo) { // Find out who received the message (username)
$query = "SELECT `uname`, `ID`
    FROM members
    WHERE ID='$userIDTo'";  
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0)
{
	$row = mysql_fetch_array($result) or die(mysql_error());
	$recipientUsername = $row['uname'];
}
return $recipientUsername;
}

mysql_select_db($database_uploader, $uploader); // Get the user's ID
$query = "SELECT `uname`, `ID`
          FROM members
          WHERE uname='$_SESSION[user]'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result) or die(mysql_error());
$userID = $row['ID'];
}

mysql_select_db($database_uploader, $uploader); // Get's all of the user's sent messages
$query = "SELECT `userIDTo`, `subject`, `ID`
          FROM memberMail
          WHERE userIDFrom='$userID' AND sent='1'";
$result = mysql_query($query) or die(mysql_error());

//Display number of unread messages
$num_rows = mysql_num_rows($result);
mysql_select_db($database_uploader, $uploader);
echo "You have ($num_rows) sent message(s): <p>";

//If there are sent messages, display them
if ($row = mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result) or die(mysql_error());

    //Open table and create headers
    echo "<table border=\"1\">\n";
    echo "  <tr>\n";
echo "    <th>Recipient</th>\n";
    echo "    <th>Subject</th>\n";
    echo "  </tr>\n";

while( $row = mysql_fetch_array($result))
{
	//Show messages
	$userIDTo = $row['userIDTo']; // Get the recipient's ID number
	$recipient = checkRecipient($userIDTo); // Get the sender's Username
	$messageID = $row['ID'];
        echo "  <tr>\n";
	echo "    <td>{$recipient}</td>\n";
        echo "    <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n";
        echo "  <tr>\n";
} 

    //Close table
    echo "</table>\n";
} else {
echo "bad"; }
?>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/247741-returning-messages/#findComment-1272186
Share on other sites

Is that the current code? Why did you put that call to mysql_fetch_array() back in that I had you remove? All it effectively does is make it so the first record retrieved won't be displayed. Also, there's no reason to use or die(mysql_error()) with mysql_fetch_array(). MySQL doesn't return an error if that fails anyhow; you'd get a php error.

Link to comment
https://forums.phpfreaks.com/topic/247741-returning-messages/#findComment-1272190
Share on other sites

//If there are sent messages, display them
if (mysql_num_rows($result) > 0) {

    //Open table and create headers
    echo "<table border=\"1\">\n";
    echo "  <tr>\n";
echo "    <th>Recipient</th>\n";
    echo "    <th>Subject</th>\n";
    echo "  </tr>\n";

while(mysql_fetch_array($result))
{
	//Show messages
	$userIDTo = $row['userIDTo']; // Get the recipient's ID number
	$recipient = checkRecipient($userIDTo); // Get the sender's Username
	$messageID = $row['ID'];
        echo "  <tr>\n";
	echo "    <td>{$recipient}</td>\n";
        echo "    <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n";
        echo "  <tr>\n";
} 

    //Close table
    echo "</table>\n";
} else {
echo "bad"; }
?>

Link to comment
https://forums.phpfreaks.com/topic/247741-returning-messages/#findComment-1272207
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.