views:

85

answers:

3

I am pulling messages from mysql using PHP to be displayed on a specific page. Instead of displaying the title of the message in the designated title bar and the message in the designated body text box...there is no content displayed and its displaying the title in the url. What am I missing in my query? Or what is going on?

/*--Here is my query--*/

$query = "SELECT * FROM `Messages` WHERE `id` = '" .$messageid. "'";
      $request = mysql_query($query,$connection) or die(mysql_error());
      $Readmessages = mysql_fetch_array($request);

       $query = "SELECT * FROM `Users` WHERE `id` = '".$Readmessages['sentFrom'] ."'";
       $request2 = mysql_query($query,$connection);
       $sender = mysql_fetch_array($request2);

/*--Here is my code--*/
A: 

When code does somthing you don't expect it to -- double check your assumptions.

1) Make sure $messageid is populated with what you need

2) Make sure the row you're returning isn't null - i.e. its working just the data is null

Tonycore
the problem is it is displaying the message body in my browser and not where I want it to in the designated body area
Ralph The Mouf
+1  A: 

First of all, you don't have to use . (append) on the $messageid - vis:

$query = "SELECT * FROM `Messages` WHERE `id` = '$messageid'";

Second, check to see if you actually returned a row and, (here's the clincher) use mysql_fetch_assoc() instead of mysql_fetch_array() - or you won't get the field names.

if ( $Readmessages = mysql_fetch_assoc($request) )
{
   $sentfrom = $Readmessages['sentFrom'];
   if (strlen($sentfrom) > 0)
   {
      $query = "SELECT * FROM `Users` WHERE `id` = '$sentfrom'";
      ...
   }
}

if you want to check your query, you can output it in your html, and look at the source:

echo "<!-- <sql>$query</sql> -->";
dar7yl
A: 

My advice is to do all your queries in a MySQL application like PHPMyAdmin and make sure you get the results you want back. Thats always what I do when I meet a problem with a query, run the query in a application so I'm sure the query itself works. If you use a mac I recommend Sequel Pro (it's free).

Sorry for the delayed help.

Josua Pedersen