我的 mysql 数据库中的数据显示不正确 [英] The data from my mysql database are not showing correctly

查看:52
本文介绍了我的 mysql 数据库中的数据显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该怎么做,它只显示一个插入的所有消息,另一个问题是当用户阅读了那里的消息时,下面的这部分代码没有显示.您可以在页面底部找到完整的代码.

此代码部分在用户阅读新消息后不会显示,但我不会显示:

 $newpm = '

Message

<div id="notificationsBody" class="notifications">您没有新消息</div>';

完整代码:

 $newpm_sql = mysql_query("SELECT * FROM `pm`WHERE `to` = '". $_SESSION['id'] ."'ORDER BY `id` DESC") 或 die(mysql_error());如果 (mysql_num_rows($newpm_sql) == 0) {$newpm = '<div id="notificationTitle">消息</div><div id="notificationsBody" class="notifications">您没有新消息</div>';} 别的 {while ( $row = mysql_fetch_array( $newpm_sql )) {$from_sql = mysql_query("SELECT * FROM `members`WHERE `id` = '". $newpm_sql['from'] ."'")或死(mysql_error());$from = mysql_fetch_array($from_sql);如果 ($row['status'] == 0) {$newpm = '<div id="notificationTitle">消息</div><div id="notificationsBody" 通知"><b><a href="page.php?name=profile&id='. $row['from'] .'">'.$row['subject'] .'</a></b><br>'.$row['text'] .''</div>';}}}

解决方案

我看到了我上次错过的错误.

本声明

$newpm = '

Message

<div id="notificationsBody" class="notifications">您没有新消息</div>';

正在 while 循环中运行,因此您应该使用 .= 将这些多次迭代连接到 $newpm 而不仅仅是一个=

 while ( $row = mysql_fetch_array( $newpm_sql )) {$from_sql = mysql_query("SELECT * FROM `members`WHERE `id` = '". $newpm_sql['from'] ."'")或死(mysql_error());$from = mysql_fetch_array($from_sql);如果 ($row['status'] == 0) {//$newpm = '<div id="notificationTitle">消息</div>newpm .='<div id="notificationTitle">消息</div><div id="notificationsBody" 通知"><b><a href="page.php?name=profile&id='. $row['from'] .'">'.$row['subject'] .'</b><br>'.$row['text'] .''</div>';}}

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>'; 
            }
        }
    }

解决方案

I see the error I missed last time.

This statement

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

is being run inside a while loop and therefore you should be concatenating these multiple iterations onto $newpm using .= and not just an =

    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>
            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>'; 
        }
    }

这篇关于我的 mysql 数据库中的数据显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆