Jump to content

Recommended Posts

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

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

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

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.