umar
umar

Reputation: 3133

Error while fetching the array

I have the following code which is generating error while fetching the elements of the array

 $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'] . " "; 

     } ?>

from the print_r(services) iam getting

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 ) 

is there any problem with while($info = mysqli_fetch_assoc($services)) it is generating error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\proj\android\services.php on line 70

Upvotes: 1

Views: 111

Answers (2)

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

No need for loop, it returns one dimensional array...

Print "<b>Name:</b> $services[starttime] "; 

Upvotes: 1

Ribose
Ribose

Reputation: 2233

It looks like

$services = $task->viewTask_front_android($_GET['pno']); 

is already returning an array (a single row, from appearance). You don't/can't fetch an array from it as if it were the result of mysql_query, because it's not.

Instead, just print $services['starttime']:

print "<b>Name:</b> ".$services['starttime'] . " ";

Edit: If I was unclear, remove the while loop completely as well.

Upvotes: 3

Related Questions