Counter problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Counter problem!

Post by cap2cap10 »

Hey php technorati. I have another problem. I am trying to create a counter that conforms to certain values that are present in the fields of a mysql db. here is my code:

Code: Select all

$query = "SELECT month, pay_type FROM js_login WHERE agentID='$_SESSION['agent_login']['agentID']' AND month= 'January' And pay_type= 'p1'";
$result = mysql_query($query) or die(mysql_error());
 
$count = '0';
while($row = mysql_fetch_assoc($result))
{
    $count ++;
}
 
echo "$count";
 
mysql_close();
 
?>
I need it to count every row that has those specific variables.But I am getting a error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Please advise captain!!!! :banghead:

Thanks in advance,

Batoe
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Counter problem!

Post by AbraCadaver »

Code: Select all

$count = mysql_num_rows($result);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
feden
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 12:58 pm

Re: Counter problem!

Post by feden »

Check the quotes!

Code: Select all

$query = "SELECT month, pay_type FROM js_login WHERE agentID='" . $_SESSION['agent_login']['agentID'] . "' AND month= 'January' And pay_type= 'p1'";
However, I think there is a better way to do it:

Code: Select all

 
$query = "SELECT COUNT(*) AS num FROM js_login WHERE agentID='" . $_SESSION['agent_login']['agentID'] . "' AND month= 'January' And pay_type= 'p1'";
 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
 
echo $row['num'];
 
Bye! :wink:
Post Reply