简体   繁体   English

语法帮助! PHP和MYSQL

[英]Syntax help! Php and MYSQL

Original: 原版的:

$sql = "SELECT DATE(TimeAdded) AS Date, $column_name FROM Codes ORDER BY TimeAdded ASC";

Altered: 已更改:

$sql = "SELECT DATE("m", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY TimeAdded ASC";

TimeAdded was added using NOW() and basically, I am trying to make it months. TimeAdded是使用NOW()添加的,基本上,我试图将其添加几个月。 The problem I have here is the quotations is messing it up. 我在这里遇到的问题是报价单弄乱了。 I tried using \\ to get rid it but no good. 我尝试使用\\摆脱它,但效果不好。 Also tried this: 还尝试了以下方法:

mysql_real_escape_string( DATE("m", TimeAdded ) ) 

More info : http://php.net/manual/en/function.date.php The date function uses m to format in months. 更多信息http : //php.net/manual/zh/function.date.php date函数使用m来格式化月份。 It's a function from PHP, I think. 我认为这是PHP的功能。

Update: I mixed the data() for php with mysql, no wonder! 更新:我将php的data()与mysql混合在一起,也就不足为奇了!

How about using the MONTH function in MySQL? 如何在MySQL中使用MONTH函数?

$sql = "SELECT MONTH(TimeAdded) AS `Date`, `ColumnName` FROM `TableName` ORDER BY `TimeAdded` ASC";

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month http://dev.mysql.com/doc/refman/5.1/zh-CN/date-and-time-functions.html#function_month

If it's a PHP function, then why not set that to a PHP variable before your query and then inject it into the query as you did the other variables? 如果它是PHP函数,那么为什么不在查询之前将其设置为PHP变量,然后像处理其他变量一样将其注入查询中呢? Just a thought. 只是一个想法。

Why didn't 为什么不

$sql = "SELECT DATE(\"m\", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY TimeAdded ASC";

Work? 工作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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