我有以下代码在获取数组元素时生成错误
$task = new task();
$task->connect();
$services = $task->viewTask_front_android($_GET['pno']);
print_r($services);
while($info = mysqli_fetch_assoc($services))
{
Print "<b>Name:</b> ".$info['starttime'] . " ";
} ?>
来自print_r(服务)的获得
Array ( [task_id] => 14 [user_id] => 123 [employee_id] => 456 [service_id] => 2 [starttime] => 2:00 AM [endtime] => 4:00 AM [servicename] => se a [servicedescription] => ddsdsd [employeename] => dsd [employeepicture] => pictures/noimage.gif [pic_path] => pictures/noimage.gif )
有什么问题吗?
while($ info = mysqli_fetch_assoc($ services))
它生成错误Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\proj\android\services.php on line 70
答案 0 :(得分:3)
看起来像是
$services = $task->viewTask_front_android($_GET['pno']);
已经返回一个数组(从外观开始的一行)。你没有/无法从中获取数组,就好像它是mysql_query
的结果一样,因为它不是。
相反,只需打印$services['starttime']
:
print "<b>Name:</b> ".$services['starttime'] . " ";
编辑:如果我不清楚,也完全删除while循环。
答案 1 :(得分:1)
不需要循环,它返回一维数组......
Print "<b>Name:</b> $services[starttime] ";