简体   繁体   English

无法从MySQL在PHP中获取完整的数组

[英]Cant get complete array in php from mysql

In phpmyadmin I Get the result expected, it means, daily number of vacations in a range of days, however I can't make it work on PHP and I get only the firs row of the whole array. 在phpmyadmin中,我得到了预期的结果,这意味着每天在几天内的休假次数,但是我无法使其在PHP上运行,而我只得到整个数组的第一行。

$mysqli = mysqli_connect("localhost", "andes", "andes123","andes");
$query= "select calendar_table.dt, count(BP) as 'Number'
from calendar_table
left join tbl021_vacaciones on calendar_table.dt between
tbl021_vacaciones.fecha_inicio and tbl021_vacaciones.fecha_fin
where (calendar_table.dt between '2016-01-29' and '2016-03-31')
group by calendar_table.dt";
$request=mysqli_query($mysqli,$query);
$row=mysqli_fetch_array($request);
$Resultado= print_r ($row['dt'], $row['Number']);

I know that I am doing it wrong, but I cannot make it work to save the results into a single PHP 我知道我做错了,但是无法将结果保存到单个PHP中

To obtain all the rows of a mysqli query: 要获取mysqli查询的所有行:

$rows = mysqli_fetch_all( $request, MYSQLI_ASSOC );

or: 要么:

while( $row = mysqli_fetch_array( $request ) )
{
    print_r( $row['dt'] );
}

MYSQLI_ASSOC means to fetch only as associative arrays. MYSQLI_ASSOC意味着仅作为关联数组来获取。 Otherwise, you will obtain both numeric and associative index, like in your example (BTW, this is not an error in your original code). 否则,您将同时获得数字索引和关联索引,就像您的示例一样(顺便说一句,这不是原始代码中的错误)。

To fetch all results you need to loop : 要获取所有结果,您需要循环:

while($row=mysqli_fetch_assoc($request)) {
 //echo $row['dt'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM