PHP 表格不显示所有数据

发布于 2024-12-18 02:15:57 字数 922 浏览 0 评论 0原文

我有一个表格,显示用户对产品撰写的评论。我遇到的问题是表格没有显示表格中的所有内容。换句话说,我想要显示的数据正在出现,但不是全部。

这是我的表的代码:

<?php

$result = mysql_query("SELECT * FROM reviews WHERE serial = '$id'")
or die(mysql_error()); ;

if (mysql_num_rows($result) == 0) {
       echo 'There Arent Any Reviews Yet';
    } else {

echo "<table width=100% border='6'><tr><th>Comments/Thoughts</th><th>Ratings</th><th>Date</th><th>User</th>";
while($info = mysql_fetch_array($result))
{
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        }
    }
echo "</tr>";
echo "</table>";
?>

当用户输入评论时,表中仅显示几个单词。似乎可以显示多少书面评论是有限制的,但我不知道在哪里更改该值。

I have a table which displays reviews written by users about products. The problem I am having is that the table isn't showing everything in the table. In other words, the data I want displayed is coming up but not the whole amount.

This is the code for my table:

<?php

$result = mysql_query("SELECT * FROM reviews WHERE serial = '$id'")
or die(mysql_error()); ;

if (mysql_num_rows($result) == 0) {
       echo 'There Arent Any Reviews Yet';
    } else {

echo "<table width=100% border='6'><tr><th>Comments/Thoughts</th><th>Ratings</th><th>Date</th><th>User</th>";
while($info = mysql_fetch_array($result))
{
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        }
    }
echo "</tr>";
echo "</table>";
?>

when a user types in a review, only a few words in the table are shown. it seems like there is a limit to how much of the written review can be shown but i do not know where to change that value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩心不撩汉 2024-12-25 02:15:57

您的 while 循环需要包含 标签(也称为表格行标签)才能正确形成表格。您还有一个格式错误的表头。

echo "<table width=100% border='6'>
          <tr> 
              <th>Comments/Thoughts</th>
              <th>Ratings</th>
              <th>Date</th>
              <th>User</th>
          </tr>"; // Missing TR here also!!
while($info = mysql_fetch_array($result))
{
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        echo "</tr>";
}
echo "</table>";

Your while loop needs to include <tr> tags (a.k.a table row tags) to correctly form the table. You also have a malformed table header.

echo "<table width=100% border='6'>
          <tr> 
              <th>Comments/Thoughts</th>
              <th>Ratings</th>
              <th>Date</th>
              <th>User</th>
          </tr>"; // Missing TR here also!!
while($info = mysql_fetch_array($result))
{
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        echo "</tr>";
}
echo "</table>";
一世旳自豪 2024-12-25 02:15:57

您的 位于错误的位置:

    while($info = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        echo "</tr>";
    }
}
echo "</table>";
?>

它看起来也没有在代码中的任何位置设置 $id 。尝试将其放在代码的顶部:

$id = mysql_real_escape_string($_GET['id']);

Your </tr> is in the wrong place:

    while($info = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $info['review']. "</td>";
        echo "<td>" . $info['ratings']. " Stars</td>";
        echo "<td>" . $info['date']. "</td>";
        echo "<td>" . $info['user']. "</td>";
        echo "</tr>";
    }
}
echo "</table>";
?>

It also looks like $id wasn't set anywhere in your code. Try putting this at the top of your code:

$id = mysql_real_escape_string($_GET['id']);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文