Jump to content

Recommended Posts

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

These are 

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

$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

Link to comment
https://forums.phpfreaks.com/topic/287017-count-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.