1

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

12
  • there is no problem with that. Commented Jul 10, 2011 at 23:20
  • 2
    The error message is pretty clear. Whatever $services is, it is not a valid MySQL result resource. Edit: It is already the result array (as you can see at the output), so no need to use mysqli_fetch_assoc. Just iterate normally over the array. Commented Jul 10, 2011 at 23:21
  • @umar: It is a valid array, but not a valid MySQL result resource. That is something different. Commented Jul 10, 2011 at 23:24
  • 1
    @umar: I already said, use a normal for or foreach loop to iterate over the array. viewTask_front_android already gave you the result. There are no DB functions involved anymore. Commented Jul 10, 2011 at 23:26
  • 1
    Btw. you might want to read this (especially the return value part) to learn what a MySQL result research actually is. This will help you understand that it is not an array. Commented Jul 10, 2011 at 23:30

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.