0

hey i want to use php mysql_fetch_array to fetch full table data at a time for that i use

while($user_details_result[]=mysql_fetch_assoc($user_details_qr));

but it returns a blank array at last like below

output:

Array
(
    [0] => Array
        (
            [user_id] => 2
            [user_name] => w
            [user_login_id] => w
            [user_login_password] => w
            [user_contacts] => w
            [user_status] => 0
            [user_post_date] => ::1
            [user_post_ip] => 2014-03-07 16:17:59
        )

    [1] => Array
        (
            [user_id] => 1
            [user_name] => q
            [user_login_id] => q
            [user_login_password] => q
            [user_contacts] => q
            [user_status] => 1
            [user_post_date] => ::1
            [user_post_ip] => 2014-03-07 16:14:23
        )

    [2] => 
)

i dont understand why 3 rd row appears..please help

1
  • can you use another loop? Commented Mar 7, 2014 at 11:11

3 Answers 3

1

Use this

while($temp=mysql_fetch_assoc($user_details_qr)) {
    user_details_result[] = $temp;
}
Sign up to request clarification or add additional context in comments.

Comments

0

mysql_fetch_assoc will return FALSE if there is no more row in the resultset. If you write FALSE into $user_details_result[], that will become a blank array.

https://www.php.net/manual/function.mysql-fetch-assoc.php

Try this

while($cur_row=mysql_fetch_assoc($user_details_qr)) {
  if($cur_row !== FALSE) { $user_details_result[] = $cur_row; }
}

But I think it should even work without the if, just like this (test it):

while($cur_row=mysql_fetch_assoc($user_details_qr)) {
  $user_details_result[] = $cur_row;
}

Comments

0

try using like this

while($row=mysql_fetch_assoc($user_details_qr))
{
     if (count($row) > 0)
          $user_details_result[] = $row;
}

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.