我想做的是拔出下表中的所有行。
$timeapp_id (this is the users id stored from session)
如果用户ID为8,则返回的值$withComma
应为“ 5 7 34”
问题是echo $withComma;
循环内的行输出上述值,但是在echo $withComma;
循环外仅返回最后一个值,因此当我$results4
仅通过最后一行(即34)时才显示该值。
我该如何解决这个问题,以便echo $withComma;
在循环外部显示所有结果,而不是最后一行?
$data2b = "select * from user_info where timesheet_approver_1 = $timeapp_id";
$result2b = mysql_query($data2b);
while ($row2b = mysql_fetch_assoc($result2b)) {
$timesheet_approver_1 = $row2b['timesheet_approver_1'];
$timesheet_approver_2 = $row2b['timesheet_approver_2'];
$user_id2 = $row2b['user_id'];
$array = array(" ",$user_id2);
$withComma = implode(" ",$array);
echo $withComma;
}
echo "<br><br>($withComma)";
$results4 = mysql_query("select * from time_data where user_id in ( $withComma ) and status = 'Submitted' order by data_date desc limit $time_entry_display_rows;");
每次循环时,您都将覆盖$array
和withComma
变量。
您需要将值累加到循环内的数组中,然后在完成循环后内陷整个数组。
$array = array();
while ($row2b = mysql_fetch_assoc($result2b)) {
$timesheet_approver_1 = $row2b['timesheet_approver_1'];
$timesheet_approver_2 = $row2b['timesheet_approver_2'];
$array[] = $row2b['user_id'];
}
$withComma = implode(", ", $array);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句