satal keto Posted March 19, 2007 Share Posted March 19, 2007 I am trying to create a simple messaging system for my website and I am having some problems with mysql_fetch_array(). the code I am using is; $query = "SELECT * FROM messages WHERE ToPlayer='" . $UserID . "'"; $result = mysql_query($query) or die(mysql_error()); $subject = "Inbox"; if (mysql_num_rows($result) > 0) { // If the user has messages $content = "<br /><table width='95%' align='center' border='1px'><tr><td>Subject</td><td>From</td><td>Date/Time</td></tr>"; while ($i = mysql_fetch_array($result, MYSQL_ASSOC)) { // For each result $MsgID = $i['MsgID']; $MsgSubject = $i['Subject']; $MsgMessage = $i['Message']; $MsgFrom = $i['FromPlayer']; $MsgDate = $i['DateSent']; $query = "SELECT Username FROM users WHERE UserID='" . $MsgFrom . "'"; $result = mysql_query($query) or die(mysql_error()); $result = mysql_fetch_array($result); $MsgFrom = $result['Username']; if ($i['Read'] == 1) { $MsgRead = true; } else { $MsgRead = false; } $content = $content . "<tr><td>"; if ($MsgRead == false) { $content = $content . "<strong>"; } $content = $content . "<a href='Msgs.php?view=Msg&MsgID=" . $MsgID . "'>" . $MsgSubject . "</a>"; if ($MsgRead == false) { $content = $content . "</strong>"; } $content = $content . "</td><td>" . $MsgFrom . "</td><td>" . $MsgDate . "</td></tr>"; } $content = $content . "</table><br />"; } The error message I am recieving is Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in L:\WOS\www\tian\Msgs.php on line 37 The code on line 37 being while ($i = mysql_fetch_array($result, MYSQL_ASSOC)) Now I have used exactly the same code in other area's of my website for the same sort of purpose but I haven't had this problem. I can't see anything wrong with that code at all but I am no expert at PHP I was wondering whether anyone else could see anything wrong with that code. Thanks for any help in advance Satal Keto Link to comment https://forums.phpfreaks.com/topic/43353-mysql_fetch_array-being-a-pain/ Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 while ($i = mysql_fetch_assoc($result)) try that. Link to comment https://forums.phpfreaks.com/topic/43353-mysql_fetch_array-being-a-pain/#findComment-210527 Share on other sites More sharing options...
satal keto Posted March 19, 2007 Author Share Posted March 19, 2007 Exactly the same error message Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in L:\WOS\www\tian\Msgs.php on line 37 Link to comment https://forums.phpfreaks.com/topic/43353-mysql_fetch_array-being-a-pain/#findComment-210531 Share on other sites More sharing options...
per1os Posted March 19, 2007 Share Posted March 19, 2007 // For each result $MsgID = $i['MsgID']; $MsgSubject = $i['Subject']; $MsgMessage = $i['Message']; $MsgFrom = $i['FromPlayer']; $MsgDate = $i['DateSent']; $query = "SELECT Username FROM users WHERE UserID='" . $MsgFrom . "'"; $result = mysql_query($query) or die(mysql_error()); $result = mysql_fetch_array($result); It is never good to use the same names twice, especially when you are in the same loop that depends on $result. Rename that far to $result2 or something like that. It should fix the problem. Link to comment https://forums.phpfreaks.com/topic/43353-mysql_fetch_array-being-a-pain/#findComment-210538 Share on other sites More sharing options...
satal keto Posted March 19, 2007 Author Share Posted March 19, 2007 I hate it when its something as obvious as that Thanks Link to comment https://forums.phpfreaks.com/topic/43353-mysql_fetch_array-being-a-pain/#findComment-210580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.