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