而在Mysql Only中拉出最后的结果?

时间:2015-02-18 12:33:07

标签: php html mysql chat messages

我得到了这个简单的脚本,遗憾的是它有一个问题,它只是拉了表格的最后一个结果,它应该取代badwords / bannedwords / smiles,这里是我所用的系统做了,谢谢!

<?php
$select=mysql_query("SELECT * FROM chat ORDER BY id DESC");
while($rows=mysql_fetch_assoc($select)) {
  $mid=$rows['id'];
  $name=$rows['name'];
  $text=$rows['message'];
  $date=$rows['date'];

  $sitechoose = mysql_query("SELECT * FROM site");
  while($change = mysql_fetch_assoc($sitechoose)){
    $o =  array($change['original'],);
    $r =  array($change['changed'],);
    $messages = str_replace($o, $r, $text);
  }
  echo "<div class='chat-content'>
        <div class='background chat-title'>
          <a href='user.php?id=".$name."'>
             <span class='user-name user-group-".$power."'>".$name."</span>
          </a>
          <div class='chat-date float-r'>
            <time datetime='2014-12-06T16:56:36+00:00'>".$date."</time>
          </div>
        </div>
        <div class='chat-message'>".$messages."</div>
       </div>";
 } 
?>

它只是拉出了在网站表中插入的最后一个结果,我想知道为什么以及如何解决它?

1 个答案:

答案 0 :(得分:2)

在查看问题后我们终于找到了它:)

<?php

    $select = mysql_query("SELECT * FROM chat ORDER BY id DESC");

    while($rows=mysql_fetch_assoc($select)) {
        $mid=$rows['id'];
        $name=$rows['name'];
        $text=$rows['message'];
        $date=$rows['date'];

        $sitechoose = mysql_query("SELECT * FROM site");

        while($change = mysql_fetch_assoc($sitechoose)) {
            $o = $change['original'];
            $r = $change['changed'];
            $text = str_replace($o, $r, $text);
        }

        echo "<div class='chat-content'><div class='background chat-title'><a href='user.php?id=".$name."'><span class='user-name user-group-".$power."'>".$name."</span></a><div class='chat-date float-r'><time datetime='2014-12-06T16:56:36+00:00'>".$date."</time></div></div><div class='chat-message'>".$text."</div></div>";
    } 

 ?>