Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in [duplicate]

Tags:

php

mysql

Possible Duplicate:
PHP: Warning: sort() expects parameter 1 to be array, resource given

Please help,

I get following Error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in......

Here is my Query:

$query = "SELECT ListNumber FROM residential"; 
$result1 = mysql_query($query); 
    if (mysql_num_rows($result1) >10){ 
        $difference = mysql_num_rows($result1) - 10; 
        $myQuery = "SELECT * FROM `residential` ORDER BY `id` LIMIT 10,". $difference; 
        $result2 = mysql_query($myQuery); 
echo $result2;
        $replace =  str_replace(", "," | ", $result2);
    while ($line = mysql_fetch_array($result2, MYSQL_BOTH))
like image 535
Corrie Avatar asked Mar 29 '11 14:03

Corrie


1 Answers

Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.

To reveal what your dynamically generated query looks like and reveal the errors, try this:

$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());

The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.

like image 119
Codecraft Avatar answered Oct 12 '22 14:10

Codecraft