当我在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.
答案 0 :(得分:2)
在第一个到达的RETURN语句中退出一个函数。
因此,您的函数只返回一个$row['status'];
。您应该将查询结果放入数组并返回它。
答案 1 :(得分:1)
您在return
循环中使用while
- 您的代码在遇到第一个return
时会退出该函数。这可能是它不起作用的原因。
答案 2 :(得分: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.