Hi Monks,
This is a piece of my code that when it runs it finds only one result based on the date I am searching on it.
But my question is why my counter is bringing out 2 instead of 1, when 1 is the times the entry was found in the database.
All I am trying to do is to count how many times a status showing 1 or 2 is inside of the table in my database.
I have many entries with status 1 and many with status 2, I am showing all the status 1 or 2 based on the date I need, I hope I explained it well.
Here is the code:
$count_sent=0;
$count_received=0;
$count_nviewed=0;
$sql = "SELECT * FROM table1 WHERE day = '$d' AND month = '$m_num' and
+ year = '$y' ";
$sth = $dbh->prepare($sql);
$sth->execute() || die $sth->errstr;
while ($pointer = $sth->fetchrow_hashref)
{
$count_sent++;
if (my $status = $pointer->{'status'} eq "2") {
$count_received++;}
if (my $status = $pointer->{'status'} eq "1") {
$count_nviewed++;}
}
#Running this it find one entry based on my date as 06/24/2004
print "My results: $count_nviewed<br>";
Thank you
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.