Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    41
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Getting an odd warning message on lines 19 & 36

    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.

    Code:
    // 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.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That error means your query result isn't what you expect. Maybe it's because of these quotes: ORDER BY 'game_date'
    Are you a Help Vampire?

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    I believe this:
    Code:
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    needs to be:
    Code:
    while ($row = mysql_fetch_array($result)) {

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by guelphdad View Post
    I believe this:
    Code:
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    needs to be:
    Code:
    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.

    Edit: the php error message from #1 post point to a error in query.
    best regards
    Last edited by oesxyl; 03-10-2009 at 02:36 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •