views:

54

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?

A: 

Without some sample code this will be harder but I think you have simply just selected the wrong fields in your MySQL query.

Josua Pedersen
Yeah that is what I am thinking. It seems like I need to incorporate or use some of the same variables from the page I am linking from? I looked at the fields and it seems correct. I will double check though. Thanks
Ralph The Mouf
/*-----query-----*/ <?php $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); ?> /*--------code------*/
Ralph The Mouf
are you printing anything from the result set to the page? the fact that you have an ' or die( etc) ' and nothing showed in your page seems to indicate that your query is fine; but from the code you pasted it seems you aren't doing anything with the results.
Mikeb
<?php $query = "SELECT * FROM Messages WHERE id = $messageid"; //No need to concatinate when you can parse it. Also when you are dealing with a ID no need for the single qoutation marks. You only need the quotes when it is a string. $request = mysql_query($query,$connection) or die(mysql_error()); $Readmessages = mysql_fetch_array($request); $fromId = $Readmessages['sentFrom']; //Did this just for readability but do concatinate if you want. $query = "SELECT * FROM Users WHERE id = $fromId"; $request2 = mysql_query($query,$connection); $sender = mysql_fetch_array($request2);?>
Josua Pedersen
My advice if the edited code above would be easier to troubleshoot 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.Sorry for the delayed help.
Josua Pedersen
A: 

I agree with Josua's answer, you probably made a mistake in your query -- or maybe you're trying to use an associative array when you fetched a normal array. Or vice versa. OR maybe you did fetch an associative array but you spelled all the fields wrong. Or possibly you did something to anger your script, and it's doing this to you to give you a hard time; later it will fix itself by magic to confuse you for days. Without any sample code, there's really no way of knowing.

Carson Myers
A: 

Your question is vague at best. What title and body are you talking about? The ones in HTML? Getting that to work right is a simple matter of printing it in the right place.

<html>
    <head>
        <title>
            <?php
                $title = getTitleFromDB();
                print($title);
            ?>
        </title>
    </head>
    <body>
        <?php
            $body = getBodyFromDB();
            print($body);
        ?>
    </body>
</html>
Eli
/*-----query-----*/ <?php $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); ?>/*--------code------*/
Ralph The Mouf