Mysql Data for month and year
I have a datepicker where the selected date will post the data by day, month, and year. I have the "by day" working, but can't seem to get the month and year to click... here is the code that works for the day.
<?php
$choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d");
$con = mysql_connect("localho开发者_如何学Cst","root","xxxxxxxxxx");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("inverters", $con);
$sql = "SELECT sum(power) AS choice FROM feed WHERE date = '".$choice."'";
$res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error());
$row = mysql_fetch_assoc($res);
echo $row['choice'].'<br />';
?>
Thanks,
Alan
Not sure if I understood what you want to do, but if you want to display data for a given month, the following sql query should work:
$sql = 'SELECT . . . WHERE month(date) = [month picked] AND year(date) = [year picked]';
Hope this helps.
精彩评论