...

View Full Version : Getting an odd warning message on lines 19 & 36



jeffmc21
03-10-2009, 12:44 AM
When I run this code, in my web page of course, I'm getting a warning message that says:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in site root folder syntax on line 19... (and another on line 36).

Here's the relevant code, minus the database connection info, and I've highlighted lines 19 and 36.


// Query the DB and retrieve the next game information from the table

$result = mysql_query("SELECT DATE_FORMAT(game_date,'%W, %M %d') AS game_day, `game_opponent`, `game_teams`, `game_times`, `game_loc` FROM `tbl_schedule` WHERE `game_date` >= CURDATE() ORDER BY 'game_date' DESC LIMIT 1");


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<div class="nextgame">
<div class="gamehead">Our Next Game:</div>
<table style:"width:95%;">
<tr>
<td class="gamedate">'.$row["game_day"].'</td>
</tr>
<tr>
<td class="opps">'. $row["game_opponent"] .'</td><td class="teams">'.$row["game_teams"].'</td>
</tr>
<tr>
<td class="gametime">'.$row["game_time"].'</td><td class="loc">'.$row["game_loc"].'</td>
</tr>
</table>
</div>';
}

mysql_free_result($result);

?>

Anyone have any ideas as to the problem? I have the almost exact same code on a different site, with the table and database names changed of course, and it works perfectly fine.

tomws
03-10-2009, 12:52 AM
That error means your query result isn't what you expect. Maybe it's because of these quotes: ORDER BY 'game_date'

guelphdad
03-10-2009, 02:17 AM
you are referencing a column in your order by, but by enclosing it in quotes you are actually referring to a string instead. Not sure if that is the error but it needs correcting.

Look into the use of mysql_error() in PHP manual, you should not be querying your database without it. If you had used it you would have seen any errors thrown from your query.

guelphdad
03-10-2009, 02:22 AM
I believe this:


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


needs to be:


while ($row = mysql_fetch_array($result)) {

oesxyl
03-10-2009, 02:33 AM
I believe this:


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


needs to be:


while ($row = mysql_fetch_array($result)) {

no, because in the rest of the code it use $row as a associative array. See for example $row["game_day"].
I guess you probably think about second to be mysql_fetch_assoc but is no difference between first and second in that case.
But this is php, :)
Except what you already said about quote I don't see anything wrong.

the php error message from #1 post point to a error in query.best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum