graham23s Posted May 13, 2007 Share Posted May 13, 2007 Hi Guys, i'm having problems getting the results from 1 of my queries, its my pm section of the site (it was working a few days ago) code: // Sent messages retrieval.../////////////////////////////////////////////////////// $query1 = "SELECT * FROM membership WHERE username='$member' LIMIT 1"; $result1 = mysql_query($query1) or die(mysql_error()); $row = mysql_fetch_array($result1); // Logged in users id...//////////////////////////////////////////////////////////// $logged_in_users_id = $row['id']; // a query to see if the messages have been read or not...////////////////////////// $query2 = "SELECT * FROM `private_messages` WHERE to_id='$logged_in_users_id'"; $result2 = mysql_query($query2) or die(mysql_error()); $row2 = mysql_fetch_array($result2); $read = $row2['read_flag']; echo $read; $query3 = "SELECT * FROM `private_messages_sent` WHERE sender_id='$logged_in_users_id' ORDER BY sentdate DESC"; $result3 = mysql_query($query3) or die(mysql_error()); // If there was no sent messages...///////////////////////////////////////////////// if (mysql_num_rows($result3) == 0) { echo '<br /><p>No Messages Sent.</p>'; } else { echo '<br /><p>My Sent Box <img src="images/msg_1.gif" border="0"></p><table width="100%" border="1" bordercolor="red" cellspacing="0" cellpadding="2"> <tr> <td bgcolor="#E6E6FA"><P>Action</td><td bgcolor="#E6E6FA"><P>Subject</td><td bgcolor="#E6E6FA" ><P>Date Sent</td><td bgcolor="#E6E6FA" ><P>To Member</td><td bgcolor="#E6E6FA" ><P>Read Status (Y/N)</td> </tr>'; } // A while to loope throught the sent messages...//////////////////////////////////// while ($row = mysql_fetch_array($result3)) { $id = $row['id']; $sendee_id = $row['to_id']; echo '<p><tr><td bgcolor="#FFFACD"><P><a href="deletesentpm.php?id='.$id.'">Delete</a></td><td bgcolor="#FFFACD"><P><a href="readpm.php?id='.$id.'"><P>'.$row['subject'].'</a></td><td bgcolor="#FFFACD"><P>'.$row['sentdate'].'</td>'; // Get the member you sent to's id.../////////////////////////////////////// $query_3 = "SELECT * FROM `membership` WHERE id='$sendee_id'"; $result_3 = mysql_query($query_3) or die (mysql_error()); $row = mysql_fetch_array($result_3); $sendee = $row['username']; $sendee_id = $row['id']; echo '<td bgcolor="#FFFACD"><p><a href="profile.php?id='.$sendee_id.'">'.$sendee.'</td><td bgcolor="#FFFACD"><p>'.$read.'</td>'; } echo '</table>'; ?> this is the query with problems: // a query to see if the messages have been read or not...////////////////////////// $query2 = "SELECT * FROM `private_messages` WHERE to_id='$logged_in_users_id'"; $result2 = mysql_query($query2) or die(mysql_error()); $row2 = mysql_fetch_array($result2); $read = $row2['read_flag']; echo $read; i'm not getting anything from it, when i do echo $query2 to see what it says its fine can nayone see any mistakes at all. thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/51241-solved-query-problem/ Share on other sites More sharing options...
john010117 Posted May 14, 2007 Share Posted May 14, 2007 Is $member defined in any part of your script? You said: WHERE username='$member' in $query1, but I didn't see that defined earlier on. Link to comment https://forums.phpfreaks.com/topic/51241-solved-query-problem/#findComment-252451 Share on other sites More sharing options...
marf Posted May 14, 2007 Share Posted May 14, 2007 one thing I like to do always for mysql Queries is $result2 = mysql_query($query2) or die(mysql_error()); if($result2){//Result Set was successful if($row2 = mysql_fetch_array($result2)){ echo "Messages Found"; } else{ echo "No Messages"; } That will double check that bit of code. You can add similar ones elsewhere. And yes you can do the Variable assignment of $row2 = blah within the If statement. Link to comment https://forums.phpfreaks.com/topic/51241-solved-query-problem/#findComment-252462 Share on other sites More sharing options...
graham23s Posted May 14, 2007 Author Share Posted May 14, 2007 Hi Guys, yep $member is defined at the very top of the page with my login check code: <?php // For register_global on PHP settings////////////////////////////////////////////// $member = $_COOKIE['member']; session_start(); // you must put this to read session variables///////////////////// if (empty($member) || !isset($member)) // fail to read the browser cookie/////////// { // Try to read session if (empty($_SESSION['member']) || !isset($_SESSION['member'])) { header("Location: login.php"); // redirect user to login////////////////////// exit; } else { $member = $_SESSION['member']; } } //Includes... ////////////////////////////////////////////////////////////////////// include("includes/db_connection.php"); include("includes/constants.php"); include("includes/header.php"); include("includes/loginnav.php"); i can't understand it, it worked a few days ago, thanks for the tip on using the else/if to test it i did it, and i got: if ($result2) { if ($row2 = mysql_fetch_array($result2)) { echo "FOUND"; } ELSE { ECHO "NOT FOUND"; } } NOT FOUND, when i echo out query2 it says: SELECT * FROM `private_messages` WHERE `to_id`='82' which is exactly what i want it to say, and it still isn't getting any info from the query! weird Graham Link to comment https://forums.phpfreaks.com/topic/51241-solved-query-problem/#findComment-252568 Share on other sites More sharing options...
graham23s Posted May 14, 2007 Author Share Posted May 14, 2007 solved guys, i don't know why it didn't work does now though. cheers Graham Link to comment https://forums.phpfreaks.com/topic/51241-solved-query-problem/#findComment-252572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.