简体   繁体   中英

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("localhost","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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM