Page 1 of 1

[Solved] "supplied argument is not a valid MySQL...&

Posted: Wed Jun 22, 2005 7:57 am
by TalonStriker
Hi i hope someone can help me with this problem:

I have this code:

Code: Select all

$id = mysql_query("SELECT 'id' FROM 'action'", $db);
	$name = mysql_query("SELECT 'name' FROM 'action'", $db);
	$description = mysql_query("SELECT 'description' FROM 'action'", $db);
	$image_source = mysql_query("SELECT 'image_source' FROM 'action'", $db);
	$game_link = mysql_query("SELECT 'game_source' FROM 'action'", $db);
	$developer = mysql_query("SELECT 'developer' FROM 'action'", $db);
	$platform = mysql_query("SELECT 'platform' FROM 'action'", $db);
	$votes_added = mysql_query("SELECT 'votes_added' FROM 'action'", $db);
	$votes = mysql_query("SELECT 'votes' FROM 'action'", $db);
	
	
	
	while (($id = mysql_fetch_array($id, MYSQL_BOTH)) && ($name = mysql_fetch_array($name, MYSQL_BOTH)) && ($description = mysql_fetch_array($description, MYSQL_BOTH)) && ($image_source = mysql_fetch_array($image_source, MYSQL_BOTH)) && ($game_link = mysql_fetch_array($game_link, MYSQL_BOTH)) && ($developer = mysql_fetch_array($developer, MYSQL_BOTH)) && ($platform = mysql_fetch_array($platform, MYSQL_BOTH)) && ($votes_added = mysql_fetch_array($votes_added, MYSQL_BOTH)) && ($votes = mysql_fetch_array($votes, MYSQL_BOTH)) ) { //line 17
		
		echo $id["action"] . " | ";
		echo $description["action"] . " | ";
		echo $image_source["action"] . " | ";
		echo $game_link["action"] . " | ";
		echo $developer["action"] . " | ";
		echo $platform["action"] . " | ";
		echo $votes_added["action"] . " | ";
		echo $votes["action"] . " | ";
		echo "<center>+------------------------------------------------------------------+</center>";
		
	}
and it gives this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vhosts/playonline.e2u.cc/action.php on line 17
i can't understand what's wrong with the code.

THANKS!!!
-TS

Posted: Wed Jun 22, 2005 8:47 am
by asmie
Hey !

why are u firing the query for each field !
Merge all the queries into 1.

Code: Select all

$result = mysql_query("SELECT *  FROM 'action'", $db); 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s Description : %s ", $row["id"], $row["name"],description); // and so on for all your fields
}

Posted: Wed Jun 22, 2005 1:14 pm
by TalonStriker
makes no difference even if I have the result all packed into 1 array. :(

I had the results go in to different arrays so it would be easier for me. (i get confused quite easily) :oops:

Posted: Thu Jun 23, 2005 1:03 am
by asmie
it makes a difference if you pack the result in a single query / result else it will affect the performance. What i mean is,every query will have to make a trip to the server and database. Hence, your script will become very slow. :)

What error are you getting ?

try printing the result you get from your query. Paste the following code in the while loop.

Code: Select all

echo "<pre>";
 print_r($row);
 echo "</pre>";

Posted: Thu Jun 23, 2005 2:32 am
by timvw
Use http://www.php.net/mysql_error, it will give you some info why something went wrong...

Code: Select all

mysql_query("SELECT 'id' FROM 'action'", $db) or die(mysql_error());
(Btw, that doesn't look like valid SQL either... SELECT id FROM action)

Re: "supplied argument is not a valid MySQL result reso

Posted: Thu Jun 23, 2005 5:01 am
by harrison
I noticed this query you wrote
TalonStriker wrote:"SELECT 'id' FROM 'action'"
Removing the single quote from the table and column names may solve it.

Code: Select all

"SELECT id FROM action"
And I suggest that you try your query first before placing it with PHP codes

Posted: Thu Jun 23, 2005 11:16 am
by TalonStriker
I was getting the following error after I sent the results to a single array:

Code: Select all

$result = mysql_query("SELECT *  FROM action", $db);// line 5
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //line 6
    echo "<pre>";
	print_r($row);
	echo "</pre>";
}
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vhosts/playonline.e2u.cc/action.php on line 6
after I include "or die(mysql_error());" i get this error
Parse error: parse error, unexpected T_STRING in /home/vhosts/playonline.e2u.cc/action.php on line 5
Because of the error the print_r doesn't produce any out put.



thanks

Posted: Thu Jun 23, 2005 7:58 pm
by harrison
usually, parse errors are committed by the line before the actual line php is telling. Try checking out line 4.

Posted: Thu Jun 23, 2005 10:27 pm
by dethron
have you connected to db?

Posted: Fri Jun 24, 2005 12:54 pm
by TalonStriker
The script is working properly now after I took out the link identfiers.
I haven't a clue why it is working since I had

Code: Select all

$db = mysql_select_db(&quote;main&quote;);
on line3
:?

Anyway thanks all!

Posted: Fri Jun 24, 2005 1:10 pm
by dethron
can you add a [SOLVED] tag to your subject?

Posted: Sat Jun 25, 2005 10:54 am
by TalonStriker
sure.
thanks again!