Jump to content

Counting Records very confused...


monkeytooth

Recommended Posts

I've tried this multiple times, it used to work like a charm too, lately though not so much. I have tried to count them 2 ways..

 

One:

$totalcount_query   = "SELECT COUNT(*) AS totalcount_rows FROM ".$tableName." ".$appndQ."";
$totalcount_result  = mysql_query($totalcount_query) or die('Error #SQL0003: Query Failed.');
$totalcount_row     = mysql_fetch_array($totalcount_result, MYSQL_ASSOC);
$totalcount = $totalcount_row['totalcount_rows'];

 

I run these within a function I created to make my code smaller in other areas of the site...

Now thing I should mention is that these still work I get record counts.. the issue with them is when ever I add an "AND" to my clause it fails.

 

Sometimes I require to find out if something or not already with a particular person so I want to count records like

 

WHERE user='$userID' AND itemID='$itemID'

The Above fails.. every time as far as getting a count with either mentioned at the top methods.

Now if I do the same thing minus the AND

 

WHERE user='$userID'

or

WHERE itemID='$itemID'

 

I get an actual count. Where am I getting this wrong?

 

 

Two:

$result = mysql_query("SELECT * FROM ".$tableName." ".$appndQ."");
$totalcount = mysql_num_rows($result);

Link to comment
https://forums.phpfreaks.com/topic/200086-counting-records-very-confused/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.