Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: COUNT error

  1. #1
    New Coder
    Join Date
    Oct 2012
    Posts
    99
    Thanks
    16
    Thanked 0 Times in 0 Posts

    COUNT error

    Hi, I have 2 functions which are meant to return the number of items a user has for sale.

    These are

    Code:
    function count_items_listed($user_id) {
    	return mysql_result(mysql_query("SELECT COUNT(`items_listed`) FROM `user_stats` WHERE `user_id` = $user_id"), 0);
    }
    
    function count_live_items_listed($user_id) {
    	return mysql_result(mysql_query("SELECT COUNT(`live_items_listed`) FROM `user_stats` WHERE `user_id` = $user_id"), 0);
    }
    To view this information, I am using

    Code:
    $count_items_listed   = count_items_listed($user_id);
    
    AND
    
    $count_live_items_listed   = count_live_items_listed($user_id);
    
    <p>Number of live items currently listed: <?php echo $count_live_items_listed; ?></p>
    <p>Number of items currently listed: <?php echo $count_items_listed; ?></p>
    The database holds three columns which contain the following test information

    user_id, items_listed, live_items_listed

    12 1 0
    12 0 1
    12 1 0

    But when I use:

    <p>Number of live items currently listed: <?php echo $count_live_items_listed; ?></p>
    <p>Number of items currently listed: <?php echo $count_items_listed; ?></p>

    The results for both show a result of 3, instead of live_items_listed being equal to 2 and items_listed equal to 1.

    Any help is much appreciated

    Paul

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,166
    Thanks
    23
    Thanked 600 Times in 599 Posts
    Re do this for your use:

    SELECT sum( `items_listed` ) , sum( `live_items_listed` )
    FROM user_stats
    WHERE user_id =12
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

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