我想从我的数据库中读取所有数据,当我从控制台运行此查询时,我得到了很多结果,但由于某种原因,php只读了一个。
$query = "
SELECT b.raw as 'address', a.raw as 'name', c.TouchTime as 'time'
FROM touchName a, touchHome b, trackTouch c
WHERE a.raw like \"%{$name}%\"
AND c.AgentID = 1
AND a.relations = b.relations
AND b.relations = c.relations
AND a.relations = c.relations
ORDER BY time desc
";
//So we can double check in the console
echo $query . "<br><br>";
$result = mysqli_query($mc, $query);
$array = mysqli_fetch_assoc($result);
//says there is only one row
$total = count( mysqli_num_rows($result) );
echo $total."<br>";
我已经尝试了很多方法来破坏结果中的数据,我已经通过多种方式修改了查询,包括分组,计数等等,试图将其分解。
加入时也相当新,如果这很难看,那是因为这是第一次没有吐出1200万个结果的黑客。
答案 0 :(得分:3)
试试这个:
$array = array();
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
答案 1 :(得分:0)
函数mysql_fetch_assoc
默认返回单个记录。
你需要迭代循环,因为@tyralcori说..
答案 2 :(得分:0)
$query = "
SELECT b.raw as 'address', a.raw as 'name', c.TouchTime as 'time'
FROM touchName a, touchHome b, trackTouch c
WHERE a.raw like \"%{$name}%\"
AND c.AgentID = 1
AND a.relations = b.relations
AND b.relations = c.relations
AND a.relations = c.relations
ORDER BY time desc
";
echo $query;
$handler= mysqli_query($mc, $query);
$result = array();
while($rec = mysqli_fetch_assoc($handler)){
$result[]['address'] = $rec['address'];
$result[]['name'] = $rec['name'];
$result[]['time'] = $rec['time'];
}
print_r($result);