13

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))
Community
  • 1
  • 1
Corrie
  • 147
  • 2
  • 3
  • 9

5 Answers5

39

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.

Codecraft
  • 7,981
  • 4
  • 25
  • 43
  • The error it gives is: Unknown column 'id' in 'order clause' – Corrie Mar 29 '11 at 14:27
  • error is bellow that line... look echo & str_replace() bellow. – Wh1T3h4Ck5 Mar 29 '11 at 14:28
  • Then your 'residential' table doesn't have a field called `id` so you can't order by it. Take that out or order by a field that you have and the query will run :-) – Codecraft Mar 29 '11 at 14:32
  • This has been sorted! Thanx for your help! – Corrie Mar 29 '11 at 14:35
  • One last problem, now it shows: Resource id #4. What does this mean? – Corrie Mar 29 '11 at 14:55
  • That means your query successfully ran and returned a resource which contains the results of it, well done! Now you need to use those results in a way only you can know how as you know what you want your program to do! – Codecraft Mar 29 '11 at 14:56
  • ya, I finally used the "or die ..." part and found out the problem for my code that was having this same issue as the questioner. Thanks so much - -turns out I had a spelling error in one of my table columns, would never have guessed it without your help. – Simon Suh Oct 12 '11 at 19:38
1

mysql_fetch_array() expects parameter 1 to be resource boolean given in php error on server if you get this error : please select all privileges on your server. u will get the answer..

Taryn
  • 234,956
  • 54
  • 359
  • 399
kavita
  • 11
  • 1
1

The code you have posted doesn't include a call to mysql_fetch_array(). However, what is most likely going wrong is that you are issuing a query that returns an error message, in which case the return value from the query function is false, and attempting to call mysql_fetch_array() on it doesn't work (because boolean false is not a mysql result object).

Hammerite
  • 20,746
  • 4
  • 67
  • 87
0

$result2 is resource link not a string to echo it or to replace some of its parts with str_replace().

http://php.net/manual/en/function.mysql-query.php

Wh1T3h4Ck5
  • 8,295
  • 9
  • 56
  • 77
  • I guess databases are not included in your massive project! :) – Wh1T3h4Ck5 Mar 29 '11 at 14:37
  • Because of this http://stackoverflow.com/questions/5483750/warning-mysql-fetch-array-expects-parameter-1-to-be-resource-array-given-in – Wh1T3h4Ck5 Mar 30 '11 at 08:50
  • Like I said, if you don't want to help then don't! You said "I guess databases are not included in your massive project! :) – Wh1T3h4Ck5 18 hours ago" then your link redirects to my new question from 2 hours ago? – Corrie Mar 30 '11 at 09:36
  • But man, read this answer... That's what I told you here before you asked another question there! Maybe you put some modifications in code, but still, that's same question. So don't wonder why you got down-votes from the other members here. But do what you want... – Wh1T3h4Ck5 Mar 30 '11 at 09:43
-1

This error comes when there is error in your query syntax check field names table name, mean check your query syntax.

Taryn
  • 234,956
  • 54
  • 359
  • 399
ukpatel
  • 21