Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso


Monk3h

Recommended Posts

Dosnt seem to like the second Line That i post (2nd line is line 4 in my Script) Can anyone tell me whats wrong with it.. I have a feeling its the +1, if so could some one please sugest another way of doing this?

 

$mytribe = mysql_fetch_array(mysql_query("select * from tribes where id=$stat[tribe]"));
$devcount = mysql_fetch_array(mysql_query("select * from dev where id=$mytribe[devcount]+1[tribe]"));

Separating out your functions and adding or die statements would be a good idea:

 

<?php
$devcount = mysql_fetch_array(mysql_query("select * from dev where id=$mytribe[devcount]+1[tribe]"));
//becomes:
$sql = "select * from dev where id=$mytribe[devcount]+1[tribe]";
$result = mysql_query($sql) or die(mysql_error().'<br />On the query:'.$sql);
$devcount = mysql_fetch_array($result);
?>

 

You'll then get told what the error is. Though i can see it - '+1[tribe]' doesn't make a lot of sense. What are you trying to do?

I'm not a pro at this by any means but yeah the +1 looks to be the problem.  I think what you're going to need to do is make a variable like this before that line:

 

$id = ($mytribe[devcount]+1) . [tribe]

 

and then in the query do....

 

from dev where id=$id

 

 

I'm probably wrong here but I think the problem is basically you're doing PHP math inside of your query where it can't be performed, that all has to be done beforehand.

 

Again I want to stress that I am very new to PHP so if someone else responds they probably know way more about it then I do.

You will get an error if your sql statement is wrong. it is not the fetching of the array that errors out it is your statement itself. That is why you should break up your variables so you can troubleshoot

 

$sql = "select * from tribes where id='".$stat['tribe']."'";
$result = mysql_query($sql) or die(mysql_error());
$mytribe = mysql_fetch_array($result);

 

If you put mysql_error() it would have told you there was an error in your statement. Also not sure what the next thing is but figure out your number before trying to filter it.

 

the [tribe] thing confuses me.

 

$newid = $mytribe['devcount']+1;
$sql2 = "select * from dev where id='$newid'";
$result2 = mysql_query($sql2) or die(mysql_error());
$devcount = mysql_fetch_array($result2);

 

Ray

Sorry for wasting your Time guys, the problem was the [tribe] Part, I removed that and it works now.. I have no idea why i put that in or What i was thinking.

 

Sorry again and thanks for your Insanely Fast Responses! :P

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.