0

My query is right but its fetch zero result so why this while loop is print ones this statement No error please tell thanks in advance

while(mysql_fetch_array($query))
{   echo "<br>"."No Error"."<br>";  }
2
  • Are you sure that your query returns zero rows? Commented Feb 11, 2012 at 11:16
  • 1
    $query? is it a string or result of mysql_query? Commented Feb 11, 2012 at 11:20

2 Answers 2

1

Please do a small debugging and put "echo mysql_num_rows($query);" just before that. It should tell you the exact number of records - and thus, the number of loops in while. mysql_fetch_array returns FALSE when no more records (or no records from the beginning).

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

1 Comment

Thanx friend this error is came because i used select query for count to default count was zero so mysql_fetch_array was working ones
0

mysql_fetch_array() method takes result of running a query on database as parameter rather than query itself and returns a row as an array.

Correct code would be:

$result = mysql_query($query);

while($row = mysql_fetch_array($result) )
{   
   echo "<br>"."No Error"."<br>";  
}

For more details on mysql_fetch_array(), have a look at:

http://php.net/manual/en/function.mysql-fetch-array.php

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.