Php Google图表每天在SQL字符串之间添加

Php Google图表每天在SQL字符串之间添加,php,mysql,foreach,google-visualization,Php,Mysql,Foreach,Google Visualization,这是密码 $search_sql = "SELECT * FROM logs WHERE from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string' "; $search_result = mysql_query($search_sql) or die(mysql_error()); $search_total = mysql_num_rows($search_result);

这是密码

$search_sql = "SELECT * FROM logs WHERE from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string' ";

$search_result = mysql_query($search_sql) or die(mysql_error());
$search_total = mysql_num_rows($search_result);

var dataTable2 = google.visualization.arrayToDataTable([
  ["Date From", "Result"],
  ["' . $from_date_string .'",  ' . $search_total2 . '],
  < INSERT LOOP EACH DATE BETWEEN HERE >
  ["' . $to_date_string .'",  ' . $search_total3 . ']
]);

我需要上面的这一点来提供从开始日期到结束日期之间的每天的信息

考虑使用查询按日期对结果进行分组,例如:

select 
    from_unixtime(timestamp, '%e %b %Y') as somedate, 
    count(*) as 'searchtotal'
from logs
where from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string'
group by somedate

这将导致“where子句”中的未知列“somedate”被编辑,以删除别名中的引号,并避免where子句中的别名。查看您的代码,我建议不要使用mysql API。自从PHP的5.5.0版本发布以来,mysql已经贬值,PHP开发团队已经宣布mysql扩展将被删除,不再受支持。另一种方法是研究使用mysqli(mysql改进版)或PDO。
select 
    from_unixtime(timestamp, '%e %b %Y') as somedate, 
    count(*) as 'searchtotal'
from logs
where from_unixtime(timestamp, '%e %b %Y') BETWEEN '$from_date_string' AND '$to_date_string'
group by somedate