Not a Valid MySQL Resource?

Discussion in 'MySQL' started by gerard0986, May 29, 2010.

  1. #1
    Keep getting this and I'm not sure whats really wrong. =/

    function get_dropdown () {
    
        global $table_games;
    
        ?>
    <form action="" name="quickselect" id="quickselect">
        <select onChange="document.location.href=this[selectedIndex].value" class="dropdown">
            <option value="#" selected="selected">- Quick Select -</option>
                <?php
                $sql = 'SELECT g_name FROM '. $table_games . 'WHERE g_status = 1 ORDER BY g_name ASC';
    
                $result = do_mysql_query($sql);
    
                if (mysql_num_rows($result) > 0) {
                    while ($row = mysql_fetch_assoc($result)) {
                        echo '<option value="'. get_game_link($row['g_name']) .'">'. $row['g_name']  .'</option>';
                    }
                }
                else {
                    echo '<option value="">No Games To Show</option>';
                }
                ?>
        </select>
    </form>
        <?php
    }
    Code (markup):

     
    gerard0986, May 29, 2010 IP
  2. edpatton

    edpatton Active Member

    Messages:
    261
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    83
    Digital Goods:
    1
    #2
    You can also contact your hosting company and a lot of times they could help you.
     
    edpatton, May 29, 2010 IP
  3. umpahpah

    umpahpah Well-Known Member

    Messages:
    266
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    quick and dirty way of seeing what is the problem is changing
    $result = do_mysql_query($sql);
    to
    $result = do_mysql_query($sql) or die(mysql_error());
    and script should stop executing and will display mysql error when you run it
     
    umpahpah, May 29, 2010 IP
  4. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The code in question is here...

    if (mysql_num_rows($result) > 0) {
    Code (markup):
    I'll try the error reporting thing though.
     
    gerard0986, May 29, 2010 IP
  5. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #5
    try to echo the table name before accessing that sql query and see if that table name variable changes
     
    chandan123, May 30, 2010 IP
  6. umpahpah

    umpahpah Well-Known Member

    Messages:
    266
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #6

    yeah but previous line is causing it.
    when you find out what is the problem with query you will know why mysql_num_rows can't handle it
     
    umpahpah, May 30, 2010 IP
  7. gerard0986

    gerard0986 Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Oh! Got it fixed somehow. Just looked at the other functions and changed it a bit. Not much though, but it worked.

    function get_dropdown () {
    
        global $table_games;
    
        $sql = 'SELECT g_name FROM '. $table_games .' WHERE g_status = 1 ORDER BY g_name ASC';
    
        $result = do_mysql_query($sql);
    
        ?>
    <form action="" name="quickselect" id="quickselect">
        <select onChange="document.location.href=this[selectedIndex].value" class="dropdown">
            <option value="#" selected="selected">- Quick Select -</option>
                <?php
    
                if (mysql_num_rows($result) > 0) {
                    while ($row = mysql_fetch_assoc($result)) {
                        echo '<option value="'. get_game_link($row['g_name']) .'">'. $row['g_name']  .'</option>';
                    }
                }
                else {
                    echo '<option value="">No Games To Show</option>';
                }
                ?>
        </select>
    </form>
    <?php
    }
    Code (markup):
     
    gerard0986, May 30, 2010 IP