php ajax聊天问题

时间:2009-12-27 20:05:56

标签: php ajax

这是我的PHP代码...........

$root = "http://localhost/";
$sql = mysql_query("SELECT * FROM mychat WHERE (too='$mid' AND froom='$uid') OR (too='$uid' AND froom='$mid') ORDER BY id ASC");
    while($ro=mysql_fetch_array($sql)){
        $from = $ro['froom'];
        $to = $ro['too'];
        $text = $ro['text'];
        $time = $ro['time'];
        $last_count = $ro['last_count'];
        echo '<li class="chat_li">
        <font face="MS Sans Serif" size="1">'.$froom.'</font></a> says: &nbsp; '.wordwrap($text, 1000,"<br>\n", true).'
            <br><font size="1" color="#777777">'.$time.'</font>
        </li>';
}   

但它只显示user1名称和所有文本,但没有显示带有文本的相应用户msg ............

我该如何解决?

我的数据库表.........

id, froom, too, text, time

这是我的输出.......... 如果user1键入........ [ssss]和user2类型..... [1244]

总是输出。

user1says:ssss 1分钟前

user1says:1244 50秒前

1 个答案:

答案 0 :(得分:1)

试试这个

$root = "http://localhost/";
    $sql = mysql_query("SELECT * FROM mychat WHERE (too='$mid' AND froom='$uid') OR (too='$uid' AND froom='$mid') ORDER BY id ASC");

    $ro= mysql_fetch_array($sql);
    for($i=0;$i< count($ro);$i++)
    {        
            $to[$i] = $ro[$i]['too'];
            $last_count[$i] = $ro[$i]['last_count'];
            echo '<li class="chat_li">

            <font face="MS Sans Serif" size="1">'.$ro[$i]['froom'].'</font></a> says:.wordwrap($ro[$i]['text'], 1000,"<br>\n", true).'
                    <br><font size="1" color="#777777">'.$ro[$i]['time'].'</font>
            </li>

}