SQL fetch Errors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Webmaster Advertising
    So Fucking Banned
    • Sep 2003
    • 1360

    #1

    SQL fetch Errors?

    Could one of the programming types give me a hand with this error that i am getting running a script on my server...

    mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/r3ading/public_html/admin/sets.php on line 175
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/r3ading/public_html/admin/sets.php on line 206
    Here are the 2 lines of code it is telling me are faulty but i dont see *why* because the script works perfectly on another server...

    174 & 175 line:
    Code:
    $query="SELECT COUNT(*) FROM $table_name";
    list($total_links)=mysql_fetch_array(mysql_query($query));
    203 to 207 lines:
    Code:
    $i=0;
    $res=mysql_query($query);
    echo "<td>";
    while($r=mysql_fetch_array($res))
    {
     $i++;
     $id=$r['id'];
     $dir_name=$r['dir_name'];
     $thumb=displayThumb($dir_name,$r['thumb']);
    Any help you could offer would be appreciated, ive been on with my hosting tech support a few times about this but theyre telling me it a 'code' issue not a server issue, but i *know* for a fact this program works 100% on another server but they wont hear any of it
  • woj
    <&(©¿©)&>
    • Jul 2002
    • 47882

    #2
    $table_name is not defined, or that table doesn't exist at all, or is perhaps corrupted... or perhaps you have wrong db credentials in your config file...

    if you want me to take a closer look for a few bucks, icq: 33375924 or woj#at#wojfun#.#com
    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

    Comment

    • AndrewX
      Confirmed User
      • Jan 2004
      • 574

      #3
      Try backing up and restoring the database tables again. Also note that 'warning' messages can be turned off in PHP configuration (debug mode), they are not errors which will halt your script.

      █ ► XenLayer - Paravirtualization Professionals since 2008 - [ICQ: 297820698]
      █ ► Reseller Hosting | OpenVZ VPS | XEN VPS | Dedicated Servers

      Comment

      • Webmaster Advertising
        So Fucking Banned
        • Sep 2003
        • 1360

        #4
        I just repaired the SQL table and that seems to have fixed it for a few minutes.

        Im now thinking there is an issue with my hosting companies SQL system perhaps?

        Every time i run the program, if i 'repair' the table afterwards it works again.

        Comment

        • AndrewX
          Confirmed User
          • Jan 2004
          • 574

          #5
          At those lines the warning appears, change mysql_fetch_array to @mysql_fetch_array

          It will make it silent.

          █ ► XenLayer - Paravirtualization Professionals since 2008 - [ICQ: 297820698]
          █ ► Reseller Hosting | OpenVZ VPS | XEN VPS | Dedicated Servers

          Comment

          • alcstrategy
            Confirmed User
            • May 2012
            • 124

            #6
            Originally posted by AndrewX
            At those lines the warning appears, change mysql_fetch_array to @mysql_fetch_array

            It will make it silent.
            you get the error because you dont check if the result is valid

            what good is making it silent if he needs for debugging assuming its not a live site and if it is a live site then set display_errors off in php config and then check error log, but add some code to handle that issue checking the result var

            Also you should move away from mysql library at the very least use mysqli. The Mysql lib will be deprecated in php's future and its an old library that lacks support in many things

            Comment

            • Webmaster Advertising
              So Fucking Banned
              • Sep 2003
              • 1360

              #7
              Well after getting on the phone with the host, it appears the error was with them blocking the server IP address from writing to SQL.

              No idea how or why this happened, but the problem is now fixed and the script is working as it should be.

              Thanks all for the assistance with this issue, its appreciated

              Comment

              • Nookster
                Confirmed IT Professional
                • Nov 2005
                • 3744

                #8
                You need to CAST the count to a named variable...

                Code:
                $query="SELECT COUNT(*) [b]AS numrows[/b] FROM $table_name";
                $ret = mysql_query($query);
                $fetched = mysql_fetch_array($ret);
                echo 'Amount = '.$fetched['numrows'];
                That's some really horrible code, btw.

                ...glad you got it sorted out.
                The Best Affiliate Software, Ever.

                Comment

                Working...