我正在尝试将我自己使用的一些谷歌图表从 mysql 升级到 mysqli程序方式,并且我在重新创建正确的数组以供谷歌图表理解时遇到困难。我想我离我很近,我失去了一些东西。欢迎任何帮助。
这是我的旧代码:
mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "select count(*) as count,visible from packs where type=1 and serial=1 group by visible";
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$data[0] = array('visible','count');
for ($i=1; $i<($totalRows_Recordset1+1); $i++)
{
$data[$i] = array(mysql_result($Recordset1, $i-1,'visible'),
(int) mysql_result($Recordset1, $i-1, 'count'));
}
结果是:
[["visible","count"],["0",266],["1",1466],["2",1],["3",59]]
但是当我升级(或尝试将代码升级到 mysqli)时:
$query_Recordset1 = "select count(*) as count,visible from packs where type=1 and serial=1 group by visible";
$Recordset1 = mysqli_query($connection,$query_Recordset1) or die(mysqli_error($mysqli));
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
# set heading
$data[0] = array('visible','count');
for ($i=1; $i<=($totalRows_Recordset1+1); $i++)
{
mysqli_data_seek($Recordset1, $i-1);
$data[$i] = array((string) mysqli_fetch_array($Recordset1)['visible'],(int) mysqli_fetch_array($Recordset1)['count']);
}
结果是:
[["visible","count"],["0",1466],["1",1],["2",59],["3",0],["",0]]
这显然与我想要的结果不匹配,因为一列由于某种原因偏移了 1(参见值 266 根本没有获取)
至尊宝的传说