简体   繁体   English

遍历mysql字段

[英]Loop through a mysql field

I'm trying to make an anonymous comment system, following is the code to print the existing comments. 我正在尝试创建一个匿名评论系统,以下是用于打印现有评论的代码。 It is requires that I loop through the comm_id field in the database to get all the comments. 要求我遍历数据库中的comm_id字段以获取所有注释。 How can I achieve this? 我该如何实现?

<ol id="update" class="timeline">
<?php
$sql=mysql_query("SELECT * from comments where com_id='' ");
while($row=mysql_fetch_array($sql) )
{
$comment=$row['comment'];
?>
<li class="box">
<?php echo $comment; ?>
</li>
<?php
}
?>

Remove where com_id='' . 删除where com_id='' This will select all of the comments unconditionally. 这将无条件选择所有注释。


Please avoid using ext/mysql and use PDO / mysqli if you can. 请避免使用ext/mysqlmysqli使用PDO / mysqli No need to use SELECT * . 无需使用SELECT * You can just select the comment column. 您只需选择comment列即可。

Try this... It will show all comments from your database table 尝试一下...它将显示数据库表中的所有注释

<ol id="update" class="timeline">
  <?php
    $sql=mysql_query("SELECT * from comments");
    while($row=mysql_fetch_array($sql) )
    {
    $comment=$row['comment'];
    ?>
    <li class="box">
    <?php echo $comment; ?>
    </li>
    <?php
    }
    ?>

remove this where com_id='' then it will consider all the comment and then display in loop: 删除where com_id=''然后将考虑所有注释,然后循环显示:

<ol id="update" class="timeline">
<?php
$sql=mysql_query("SELECT * from comments  ");
while($row=mysql_fetch_array($sql) )
{
$comment=$row['comment'];
?>
<li class="box">
<?php echo $comment; ?>
</li>
<?php
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM