SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_num_rows(): supplied argument is not a valid MySQL result resource

    I have this very basic script to show some data from a DB in an HTML page. This is code I used a long time ago and it all worked okay, now I am getting this error: [img]images/smilies/frown.gif[/img]

    "mysql_num_rows(): supplied argument is not a valid MySQL result resource"

    Could someone please help me figure out what the correct way to do this is. I am using PHP 4.3.1. Thank you ! [img]images/smilies/smile.gif[/img]
    Code:
    <?
    $db=mysql_connect ("localhost", "user", "pass" )
    or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db("average_payment",$db);
    
    $sql="SELECT * FROM $id ORDER BY title DESC LIMIT 0,100000";
    $result=mysql_query($sql,$db);
    $num = mysql_num_rows($result);
    $cur = 1;
    
    print("
    <table class=border cellpadding=3 cellspacing=6>
    <tr>
    <td><u><b>Player Name</b></u></td>
    <td><u><b>May</b></u></td>
    <td><u><b>June</b></u></td>
    <td><u><b>July</b></u></td>
    <td><u><b>August</b></u></td>
    <td><u><b>September</b></u></td>
    <td><u><b>October</b></u></td>
    <td><u><b>November</b></u></td>
    <td><u><b>December</b></u></td>
    </tr>" );
    
    while ($num >= $cur) {
    $row = mysql_fetch_array($result);
    $id = $row["id"];
    $player_name = $row["player_name"];
    $May = $row["May"];
    $June = $row["June"];
    $July = $row["July"];
    $August = $row["August"];
    $September = $row["September"];
    $October = $row["October"];
    $November = $row["November"];
    $December = $row["December"];
    
    print("
    <table class=border cellpadding=3 cellspacing=6>
    <tr>
    <td><u><b>$player_mame</b></u></td>
    <td><u><b>$May</b></u></td>
    <td><u><b>$June</b></u></td>
    <td><u><b>$July</b></u></td>
    <td><u><b>$August</b></u></td>
    <td><u><b>$September</b></u></td>
    <td><u><b>$October</b></u></td>
    <td><u><b>$November</b></u></td>
    <td><u><b>$December</b></u></td>
    </tr>" );
    
    $cur++;
    }
    
    print("</table>" );
    ?>

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql="SELECT * FROM $id ORDER BY title DESC LIMIT 0,100000";
    what is $id? and print $sql

  3. #3
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As sylow implied, the error is coming from the sql query (bad query - no result pointer to pass to the mysql_num_rows() function; error shows up there).

    You can find out the exact sql error by using php's mysql_error function like this:

    PHP Code:
    $result=mysql_query($sql,$db) or die(mysql_error()); 
    That should help you better troubleshoot the problem.
    Mr Vector
    High quality, royalty free, vector graphics
    for t-shirt artists and graphic/web designers.

  4. #4
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was my select statement, I was calling the wrong table name. Sry to waste your time, thank you for atempting to help me.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Kampala Uganda
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this statement:-BY Default _num is represented by mysql_fetch_row you dont have to repeat ie mysql_num_row. If you want to use num then better is
    PHP Code:
     $row mysql_fetch_array($resultsMYSQL_NUM
    Still having problems????
    And we know that all things work together for good
    To them that love God, to them who are the called
    According to his purpose. Romans 8:28

  6. #6
    ǖber abstrakt's Avatar
    Join Date
    Dec 2001
    Location
    Earth
    Posts
    261
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by abstrakt
    It was my select statement, I was calling the wrong table name. Sry to waste your time, thank you for atempting to help me. [img]images/smilies/smile.gif[/img]


Bookmarks

Posting Permissions

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