Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

php - The data from my mysql database are not showing correctly

How do i do so it show all messages insted of only one, and other problem is that when the user have read there message and this part of the code right below are not showing. The full code can you find at the bottom of the page.

THIS CODE PART ARE NOT SHOWING AFTER A USER HAVE READ THERE NEW MESSAGE, BUT I WILL NOT SHOW:

    $newpm = '<div id="notificationTitle">Message</div>
    <div id="notificationsBody" class="notifications">You have no new messages</div>'; 

THE FULL CODE:

    $newpm_sql = mysql_query("SELECT * FROM `pm` 
                              WHERE `to` = '". $_SESSION['id'] ."' 
                              ORDER BY `id` DESC") or die(mysql_error());

    if (mysql_num_rows($newpm_sql) == 0) { 
        $newpm = '<div id="notificationTitle">Message</div>
        <div id="notificationsBody" class="notifications">You have no new messages</div>'; 
    } else {
        while ( $row = mysql_fetch_array( $newpm_sql )) {

            $from_sql = mysql_query("SELECT * FROM `members` 
                                     WHERE `id` = '". $newpm_sql['from'] ."'") 
                   or die(mysql_error());
            $from = mysql_fetch_array($from_sql);

            if ($row['status'] == 0) { 
                $newpm = '<div id="notificationTitle">Message</div>
                          <div id="notificationsBody" notifications">
<b><a href="page.php?name=profile&id='. $row['from'] .'">'. $row['subject'] .'</a></b><br> '. $row['text'] .'
                           '</div>'; 
            }
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First run this:

SELECT * FROM `pm` WHERE `to` = '<your SESSION ID>'
ORDER BY `id` DESC

and see if that returns something.

You can also do:

var_dump(mysql_num_rows($newpm_sql));die;  

after running this mysql_query in first line and see if it returns something you expect.

And also, you can switch to PDO - you will not regret it, as you're now using old php functions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...