www.webdeveloper.com
Results 1 to 2 of 2

Thread: Resource id #3 HELP!!!!

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    1

    Resource id #3 HELP!!!!

    Hi,

    I am a total novice, trying to just return a count from a table, but I keep getting a Resource id #3, I see this is a common problem but I dont understand stuff I have read to know how to modify my code.

    Code:
    <?php
    require('LogbookSearchConfig.php');
    $db=MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
    
    @mysql_select_db("$dbName") OR DIE(error(mysql_error()));
    
            $call = isset($_POST['call']) ? $_POST['call'] : '';
            $MyCall = isset($_POST['MyCall']) ? $_POST['MyCall'] : '';
            $cate = isset($_POST['cate']) ? $_POST['cate'] : '';
                            if ($call == "")
                        {$call = '';}
                            if ($MyCall == "")
                        {$MyCall = '';}
                      
        $query = 'SELECT count(*) FROM `OnlineLogBook` WHERE date >= \'2013/01/01\''; 
                
                $result = @MYSQL_QUERY($query);
                $num_rows = @mysql_num_rows($result); 
                
                echo "$result";
                
                  MYSQL_CLOSE($db);
                            exit;
       ?>
    I know the SQL works but getting the number out into a webpage is defeating me!!!

    Help!

    regards

    Bob

  2. #2
    Join Date
    Jul 2007
    Location
    Wisconsin
    Posts
    468
    It's showing "Resource #3" because $result is just that. a MySQL Resource.

    http://www.php.net/manual/en/function.mysql-query.php

    For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

    The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data
    You need to loop over the result with:

    PHP Code:
    while ($row mysql_fetch_assoc($result)) {
        echo 
    $row["count(*)"];

    Although, I'm not sure why you would need to do that, because your query would return the same thing as the mysql_num_rows.

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