我想回显用户表中的所有 ID,但我无法让它工作。我在下面尝试了这个并搜索了一些堆栈,但我找不到正确的答案。
$query = $db->query( "SELECT * FROM users" );
$num = $db->num( $query );
while( $array = $db->assoc( $query ) ) {
$active_ids = $array['id'];
}
$query = "SELECT u.username, u.habbo, count(*) AS n
FROM users u, timetable tt
WHERE u.id=tt.dj and u.id IN (".$active_ids.")
GROUP BY tt.dj";
$result = $mysqli->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()){
echo "<tr id='uren-table-row'>";
echo "<td width='60px'><div style='height:50px;padding-top:25px;overflow:hidden;float:left;margin-top:-25px;'><img style='margin-top:-28px;float:left;' src='http://habmoon.org/moonstream/dj?habbie={$row['habbo']}&head_direction=3&direction=2&size=b&hb=img&gesture=sml'></div></td>";
echo "<td width='200px' style='padding:0 15px;'>", $row['username'] ,"</td>";
echo "<td style='padding:0 15px;'>Heeft <b>", $row['n'] ,"</b> Uur gedraait deze week</td>";
echo "</tr>";
}
}
最佳答案
从您的查询中删除 count(*) AS n
。这将导致 MySQL 只返回 1 条记录。
你的第一行也有一些错误:
$active_ids = array();
while( $array = $db->assoc( $query ) ) {
$active_ids[] = $array['id'];
}
您忘记定义 $active_ids
并添加 []
。
关于php - 从表 MYSQL 中获取所有 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33446039/