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!
$getDistinctDays = mysql_query("SELECT DISTINCT Date
FROM phonelog2
WHERE Date>='$start_date'
AND Date<='$end_date' ");
while ($row = mysql_fetch_array($getDistinctDays))
{
$countTotalPerDay = mysql_query("SELECT COUNT( * )
FROM phonelog2
WHERE Date=$row['Date'] ");
}
Error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/public5/public_html/testing/alex_testing/phonequerynew.php on line 251
SELECT DISTINCT
pl.`DATE`,
(SELECT count(*) FROM phonelog2 pl2 WHERE pl2.`DATE` = pl.`DATE`) as Total
FROM
phonelog2 pl
WHERE
pl.`DATE`>='$start_date'
AND pl.`DATE`<='$end_date'
Actually, I believe you need backticks around the Date field as well.
If we're on the subject of code cleanup, make sure you've properly escaped $start_date/$end_date; better yet, use a DB parameter binding wrapper (AdoDB is a pre-canned one, but it shouldn't take more than five minutes to code your own.)
$getDistinctDays = mysql_query("SELECT DISTINCT Date
FROM phonelog2
WHERE Date>='$start_date'
AND Date<='$end_date' ");
while ($row = mysql_fetch_array($getDistinctDays))
{
$countTotalPerDay = mysql_query("SELECT COUNT( * )
FROM phonelog2
WHERE Date={$row['Date']}");
while ($row = mysql_fetch_array($countTotalPerDay))
{
echo $row[what goes here?];
}
}
Ambush Commander wrote:If we're on the subject of code cleanup, make sure you've properly escaped $start_date/$end_date; better yet, use a DB parameter binding wrapper (AdoDB is a pre-canned one, but it shouldn't take more than five minutes to code your own.)
Will do, next on my list. Just getting the skeleton running then I'll go through and clean it up.
$getDistinctDays = mysql_query("SELECT DISTINCT Date
FROM phonelog2
WHERE Date>='$start_date'
AND Date<='$end_date' ");
while ($row = mysql_fetch_array($getDistinctDays))
{
echo $row['Date'];
echo "<br>";
}