Click to See Complete Forum and Search --> : Simple Problem displaying results of query


jeffmc21
12-10-2009, 03:06 PM
I'm able to connect to the db with no problem and have had this code work before on another site (save the changes of the tbl name, etc), but now I'm getting an error that says:
mysql_fetch_array(): supplied argument is not a valid MySQL result resouce in ... on line 18 (which is the line where the while statement begins)

Any ideas as to why it's not working? I literally copied and pasted from my code on another site where it worked for me.


$result = mysql_query("SELECT DATE_FORMAT(game_date,'%W, %M %d') AS game_night, `game_img`, `game_title`, `game_loc`, `game_direct` FROM `tbl_basketball` 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>
<div class="gameicon"><img src="'.$row["game_img"].'" width="124" height="58" /></div>
<div class="gamedate">'.$row["game_night"].'</div>
<div class="game">'. $row["game_title"] .'</div>
<div class="loctime"><div class="loc">'. $row["game_loc"] . '</div><div class="time">'. $row["game_time"] . '</div></div>
<div class="direct">'.$row["game_teams"].'</div>
</div>';
}

svidgen
12-10-2009, 03:22 PM
Add a mysql_error() dump in there and tell us what you see ...

$result = mysql_query("SELECT DATE_FORMAT(game_date,'%W, %M %d') AS game_night, `game_img`, `game_title`, `game_loc`, `game_direct` FROM `tbl_basketball` WHERE `game_date` >= CURDATE() ORDER BY 'game_date' DESC LIMIT 1");

if (!$result) {
print "<div>MySQL error: " . mysql_error() . "</div>";
} else {


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<div class="nextgame">
<div class="gamehead">Our Next Game:</div>
<div class="gameicon"><img src="'.$row["game_img"].'" width="124" height="58" /></div>
<div class="gamedate">'.$row["game_night"].'</div>
<div class="game">'. $row["game_title"] .'</div>
<div class="loctime"><div class="loc">'. $row["game_loc"] . '</div><div class="time">'. $row["game_time"] . '</div></div>
<div class="direct">'.$row["game_teams"].'</div>
</div>';
}

} // end ELSE

jeffmc21
12-10-2009, 03:43 PM
found it.

Thanks so much for your help. It immediately showed me that I had one of the old column names in the query that didn't match up.

Fixed and working well.