[Web error] Expects paramater 1 to be resource

04/23/2011 06:42 KiiDxLaggy#1
I am getting this error
Code:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pages\nobility.php on line 15
any ideas?
04/23/2011 06:47 Eurion#2
Can you post lines 10 - 20 of your nobility.php file please.
04/23/2011 06:52 KiiDxLaggy#3
Quote:
Originally Posted by Eurion View Post
Can you post lines 10 - 20 of your nobility.php file please.

Code:
		<h1>Nobility Ranking</h1>

<table width="100%" border="0">
    <tr>
  <th width="20%" align="center"><b>Rank</b></th>
  <th width="20%" align="center"><b>User name</b></th>
  <th width="20%" align="center"><b>Gold Donated</b></th>
    </tr>
<h2></h2>
<?php

    $rank = mysql_query("SELECT * FROM cq_donation_dynasort_rec ORDER by value desc limit 20");
    //$row = mysql_fetch_array($rank);
    $i=1;
    while($row = mysql_fetch_array($rank)){
    echo '
    <td><div align="center">'.$i.'-</td></div>
    <td><div align="center">'.$row['user_name'].'</td></div>
    <td><div align="center">'.$row['value'].'</td></div>
   </tr> ';
  $i=$i+1;
    }

?></tr>
</table>
That is the whole file. This error is also happening in all the other pages that require mySQL also. I am using a website that Elite4Demons released, heres my site if you wanna see what im talking about:
HTML Code:
http://nextgengaming.no-ip.org
04/23/2011 07:06 Eurion#4
Are you sure, that your mysql is working correctly? I've tested that code, and there's nothing missing in it.

Looked at your source. It seems like your php is set so it doesnt load ASP like tags. To fix this, just edit your codes so that all your php tags are changed from like:

Code:
<? 

require("config.php");

?>
to
Code:
<?php 

require("config.php");

?>
04/23/2011 07:11 KiiDxLaggy#5
Yah pretty sure.. I just it and it works fine, i can connect to navicat and all, uhm.. I added you on MSN maybe this would be easier if you try to help on there? I wont bug you >.>
04/23/2011 07:18 PowerChaos#6
Quote:
Originally Posted by KiiDxLaggy View Post
I am getting this error
Code:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pages\nobility.php on line 15
any ideas?
as far as the text says

it dit not return a valid result or it is called muliple times

more info can be found on the quotes i took from other forums

Quote:
Originally Posted by a other forum
deMorte - 12:59 pm on Jul 22, 2008 (gmt 0)


Where are you calling the function numrows()?
The error code states that you are sending a boolean to the function and you should be sending a mysql resource. This resource comes from a valid mysql query.
Maybe the sql query you are making is not valid and produces a FALSE boolean and then you are trying to send this boolean to the numrows() function.
Quote:
Originally Posted by other post from a forum
eelixduppy - 4:45 am on Jul 23, 2008 (gmt 0)


It means that wherever you are calling the function numrows($var) the $var isn't a valid argument. It should be the result from mysqli_query. The code that you have given us is correct. You are calling the function numrows somewhere else in your code and that is what is creating the error.
Greets From PowerChaos
04/23/2011 07:29 Eurion#7
None of those are correct. His issue was that the site uses the ASP type opening tags such as <? instead of the typical <?php . When changed it worked as planned.
04/23/2011 07:59 KiiDxLaggy#8
Quote:
Originally Posted by Eurion View Post
Are you sure, that your mysql is working correctly? I've tested that code, and there's nothing missing in it.

Looked at your source. It seems like your php is set so it doesnt load ASP like tags. To fix this, just edit your codes so that all your php tags are changed from like:

Code:
<? 

require("config.php");

?>
to
Code:
<?php 

require("config.php");

?>
This was the problem! thanks.
04/23/2011 17:00 PowerChaos#9
i am basicly wondering what asp tags has to do with boolean

if i am not wrong
if you use short tags when not supported then php does not get executed ??
maybe that can return that error as it is expecting a value but can not get a value as it does not get executed ??

anyway
i am happy that the problem is solved

Greets From PowerChaos
04/23/2011 17:18 Eurion#10
Quote:
Originally Posted by PowerChaos View Post
i am basicly wondering what asp tags has to do with boolean

if i am not wrong
if you use short tags when not supported then php does not get executed ??
maybe that can return that error as it is expecting a value but can not get a value as it does not get executed ??

anyway
i am happy that the problem is solved

Greets From PowerChaos
Without the ASP tags turned on, the php will not compile the code and spit it out. So in his case, it wasn't loading his config.php file.

The "resource" error was caused because the mysql connection was included inside his config.php file which wasn't being read.