0

当我在 phpMyAdmin 中运行此查询时,它会加载所有行。但是当我通过 PHP SQL 运行它时,我只得到第一行。我不确定我在这里做错了什么,我真的很紧张。

这是我的代码:

    function getRows($user)
{
    $q = mysql_query("SELECT day(closed) AS day, COUNT( closed ) AS c FROM ost_ticket WHERE year(closed) = '2013' AND monthname(closed) = 'January' AND source = '{$user}'  GROUP BY day LIMIT 30");
    $count = mysql_num_rows($q);
    return $count;
}
function test11($user)
{
    $q = mysql_query("SELECT * FROM ost_ticket WHERE closed LIKE  '%2013-06-   19%' AND source = '" . $user. "'");
       if(!$q)
    {
        echo mysql_error();
    }
 $r = 0;
$a = mysql_num_rows($q);
echo $a;
while($row = mysql_fetch_assoc($q))
{   
return $row['status'];
return $row['day'];
$r++;
}
}
 function getUser()
 {
    $q = mysql_query("SELECT * FROM ost_staff WHERE staff_id > 2");
    while($row = mysql_fetch_assoc($q))
    {
            $count1 = getRows($row['username']);
            $a = 0;
        echo '<div id="' . $row['username'] . '" class="stat">
        <span class="title">' . $row['username'] . '</span><br /><br />
        <div id="break"></div>';
        echo '
        <div id="data-' . $row['username'] .'">' . test11($row['username'])   . '</div>';
    echo '</div>';
    }
}

Thanks in advance for this.
4

3 回答 3

2

函数在第一个到达的 RETURN 语句时退出。

所以,你的函数只返回一个$row['status'];。您应该将查询结果放在一个数组中并返回它。

于 2013-06-19T13:08:50.840 回答
1

returnwhile循环中使用 - 您的代码在第一次遇到时退出该函数return。这可能是它不起作用的原因。

于 2013-06-19T13:08:57.327 回答
0

这里:

while($row = mysql_fetch_assoc($q))
{   
    return $row['status']; //Returns in only this value
    return $row['day'];
    $r++;
}

使固定:

$a = array()
while($row = mysql_fetch_assoc($q))
{   
    $a['status'][] =  $row['status'];
    $a['day'][] = $row['day'];
    //$r++;
}
return $a; //This will return an array with all the rows fetched.
于 2013-06-19T13:11:56.933 回答