PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
TalonStriker
Forum Newbie
Posts: 8 Joined: Thu May 26, 2005 2:56 pm
Post
by TalonStriker » Wed Jun 22, 2005 7:57 am
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
Last edited by
TalonStriker on Sat Jun 25, 2005 10:55 am, edited 1 time in total.
asmie
Forum Newbie
Posts: 11 Joined: Mon Jun 20, 2005 8:45 am
Post
by asmie » Wed Jun 22, 2005 8:47 am
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
}
TalonStriker
Forum Newbie
Posts: 8 Joined: Thu May 26, 2005 2:56 pm
Post
by TalonStriker » Wed Jun 22, 2005 1:14 pm
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)
asmie
Forum Newbie
Posts: 11 Joined: Mon Jun 20, 2005 8:45 am
Post
by asmie » Thu Jun 23, 2005 1:03 am
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>";
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Jun 23, 2005 2:32 am
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)
harrison
Forum Commoner
Posts: 30 Joined: Thu Jun 09, 2005 12:23 am
Post
by harrison » Thu Jun 23, 2005 5:01 am
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.
And I suggest that you try your query first before placing it with PHP codes
TalonStriker
Forum Newbie
Posts: 8 Joined: Thu May 26, 2005 2:56 pm
Post
by TalonStriker » Thu Jun 23, 2005 11:16 am
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
harrison
Forum Commoner
Posts: 30 Joined: Thu Jun 09, 2005 12:23 am
Post
by harrison » Thu Jun 23, 2005 7:58 pm
usually, parse errors are committed by the line before the actual line php is telling. Try checking out line 4.
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Thu Jun 23, 2005 10:27 pm
have you connected to db?
TalonStriker
Forum Newbie
Posts: 8 Joined: Thu May 26, 2005 2:56 pm
Post
by TalonStriker » Fri Jun 24, 2005 12:54 pm
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("e;main"e;); on line3
Anyway thanks all!
dethron
Forum Contributor
Posts: 370 Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul
Post
by dethron » Fri Jun 24, 2005 1:10 pm
can you add a [SOLVED] tag to your subject?