SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Grand Rapids, MI
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error when pulling MySQL info

    I've got some code that I thought should've been easy to make. All I want is to have a page displaying some info, thats all I want, but I get the following error...

    HTML Code:
    Connected to MySQL
    
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/fansn/public_html/test1.php on line 13
    
    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/fansn/public_html/test1.php on line 16
    here's the code...

    Code:
    <?php
    
    $username = "myusername";
    $password = "mypass";
    $hostname = "localhost";	
    $dbh = mysql_connect($hostname, $username, $password) 
    	or die("Unable to connect to MySQL");
    print "Connected to MySQL<br>";
    
        $dltable = 'nuke_downloads_downloads';
    
      $result1 = mysql_query("SELECT sum(pn_hits) AS count FROM $dltable");
      $total_downloads = mysql_result($result1,0,"count");
    
        $result2 = mysql_query("SELECT sum(pn_hits*pn_filesize) AS count FROM $dltable");
        $cats_1 = mysql_result($result2,0,"count");
    
    
        $total_cats = $cats_1 / 1073741824;
    
    ?>
    someone help me out please!

  2. #2
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try replacing this code:
    PHP Code:
      $result1 mysql_query("SELECT sum(pn_hits) AS count FROM $dltable");
      
    $total_downloads mysql_result($result1,0,"count");

        
    $result2 mysql_query("SELECT sum(pn_hits*pn_filesize) AS count FROM $dltable"); 
    with this:
    PHP Code:
      $result1 mysql_query("SELECT sum($pn_hits) AS count FROM $dltable");
      
    $total_downloads mysql_result($result1,0,"count");

        
    $result2 mysql_query("SELECT sum($pn_hits*$pn_filesize) AS count FROM $dltable"); 

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Grand Rapids, MI
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still getting the same error. pn_hits is a column in the table, as is pn_filesize if that helps at all.

    Code:
    <?php
    
    $username = "myusername";
    $password = "mypass";
    $hostname = "localhost";	
    $dbh = mysql_connect($hostname, $username, $password) 
    	or die("Unable to connect to MySQL");
    print "Connected to MySQL<br>";
    
        $dltable = 'nuke_downloads_downloads';
    
     $result1 = mysql_query("SELECT sum($pn_hits) AS count FROM $dltable"); 
      $total_downloads = mysql_result($result1,0,"count");
    
        $result2 = mysql_query("SELECT sum($pn_hits*$pn_filesize) AS count FROM $dltable"); 
        $cats_1 = mysql_result($result2,0,"count");
    
    
        $total_cats = $cats_1 / 1073741824;
    
    ?>

  4. #4
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Grand Rapids, MI
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone see any problem with that code?!?!? it should work!!!

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Change the lines,
    PHP Code:
    $result1 mysql_query("SELECT sum($pn_hits) AS count FROM $dltable") or die(mysql_error()); 
    and
    PHP Code:
    $result2 mysql_query("SELECT sum($pn_hits*$pn_filesize) AS count FROM $dltable") or die(mysql_error()); 

    The or die(mysql_error()); will give you (and us) more of an idea where the query is failing. It might be that something in your database isn't playing ball or something in the script.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try selecting your database!

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by WhSox21
    Try selecting your database!
    yup, that would help! :/
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •