www.webdeveloper.com
Results 1 to 6 of 6

Thread: Resource id #5 ???

  1. #1
    Join Date
    Dec 2005
    Posts
    193

    Resource id #5 ???

    hi, I'm trying to get a script working but keep getting an error, Resource id #5

    here's the code:
    PHP Code:
    <?php                                    
                                                                                                
    $dbh 
    mysql_connect($dbhost,$dbuser,$dbpass)
        or die (
    mysql_error());    
    mysql_select_db("home_protree") or die(mysql_error());

    // Get all the data from the  table
    $result mysql_query("SELECT AVG(rctt) FROM name"
    or die(
    mysql_error());  

    echo 
    "<table border='1'>";
    echo 
    "<tr> <th>Name</th> <th>Average</th> </tr>";
        echo 
    "<tr><td width=125>"
        echo 
    "All Users";
        echo 
    "</td><td width=125>"
        echo 
    $result;
        echo 
    "</td></tr>"

    echo 
    "</table>";
    ?>

  2. #2
    Join Date
    Feb 2003
    Posts
    2,745
    cant echo $result. need to echo members of $result. try this
    PHP Code:
    <?php                                     
                                                                                                 
    $dbh 
    mysql_connect($dbhost,$dbuser,$dbpass
        or die (
    mysql_error());     
    mysql_select_db("home_protree") or die(mysql_error()); 

    // Get all the data from the  table 
    $result mysql_query("SELECT AVG(rctt) as av FROM name"
    or die(
    mysql_error());   

    echo 
    "<table border='1'>"
    echo 
    "<tr> <th>Name</th> <th>Average</th> </tr>"
        echo 
    "<tr><td width=125>"
        echo 
    "All Users"
        echo 
    "</td><td width=125>"
        echo 
    $result['av'];
        echo 
    "</td></tr>"

    echo 
    "</table>"
    ?>
    also, assuming you have a table called "name"...

  3. #3
    Join Date
    Dec 2005
    Posts
    193
    Yes, I do, a table called name and a field called name in the table. It's my first go round with MySQL.

    any how the resuorce id #5 disappeared but the box is now blank??

    I also tried:
    $result['AVG(rctt)'];

    with the same blank result... hmm...

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    sounds like SELECT AVG(rctt) as av FROM name is returning null. any nulls in the rctt column?

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,312
    You need to use a mysql_fetch_*() function to retrieve each row from the result set.
    PHP Code:
    <?php                                    
                                                                                                
    $dbh 
    mysql_connect($dbhost,$dbuser,$dbpass)
        or die (
    mysql_error());    
    mysql_select_db("home_protree") or die(mysql_error());

    // Get all the data from the  table
    $result mysql_query("SELECT AVG(rctt) AS av FROM name")
    or die(
    mysql_error());  
    $row mysql_fetch_assoc($result) or die("No rows returned by query");
    echo 
    "<table border='1'>";
    echo 
    "<tr> <th>Name</th> <th>Average</th> </tr>";
        echo 
    "<tr><td width=125>";
        echo 
    "All Users";
        echo 
    "</td><td width=125>";
        echo 
    $row['av'];
        echo 
    "</td></tr>";

    echo 
    "</table>";
    ?>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Dec 2005
    Posts
    193
    WOW, Thanks NogDog!! Worked like a champion!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles