双数据结果mysql_fetch_array

时间:2013-12-14 12:00:32

标签: php mysql while-loop

我想像在桌子上一样显示数据

<?php
while(my looping data){
$selectorang2 = mysql_query("SELECT likes.*, user.* FROM likes, user WHERE 
                 likes.uid_fk = u ser.uid AND 
                 likes.idstatus_fk = $data[idstatus]");
while ($peoplelike = mysql_fetch_assoc($selectorang2)) {
    $datajempoler2[] = $peoplelike['nama'];
}
    echo count($datajempoler2);
}
?>

结果是

2 4 6 8 10 12等。

表上的数据是2 2 2 2 2 2等。 任何人都可以帮我,我在谷歌这么累了搜索。

先谢谢。

2 个答案:

答案 0 :(得分:2)

您需要重新初始化datajempoler2数组,否则它会保留旧值并向其中添加新元素。

<?php
while(my looping data) {
    datajempoler2 = array(); // this line need to be added

    $selectorang2 = mysql_query("SELECT likes.*, user.* FROM likes, user WHERE 
                 likes.uid_fk = u ser.uid AND 
                 likes.idstatus_fk = $data[idstatus]");

    while ($peoplelike = mysql_fetch_assoc($selectorang2)) {
        $datajempoler2[] = $peoplelike['nama'];
    }

    echo count($datajempoler2);
}
?>

答案 1 :(得分:0)

因为在这里:

  while ($peoplelike = mysql_fetch_assoc($selectorang2)) {
        $datajempoler2[] = $peoplelike['nama'];
    }

你在那里设置数组$ datajempoler2两次,在你做回声之后,得到:2,4,6等等