[英]UNIX_TIMESTAMP Function MySQL
Any idea why this wont work?知道为什么这不起作用吗? I have a feeling its the row name I have given it.
我有一种感觉,它是我给它的行名。 It doesnt echo anything
它没有回应任何东西
$result = mysql_query("SELECT UNIX_TIMESTAMP(datetime) FROM voters WHERE ip='$ip'") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$unixtimestamp = $row['UNIX_TIMESTAMP(datetime)'];
echo $unixtimestamp;
}
Nevermind, datetime is not a reserved word, but I still highly recommend not using it and choosing a better column name.没关系,datetime 不是保留字,但我仍然强烈建议不要使用它并选择更好的列名。 :), but the below still stands.
:),但下面仍然存在。
Alias the column, makes pulling it out in the array easier later on:为列命名,以便以后更容易将其从数组中拉出:
$result = mysql_query("SELECT UNIX_TIMESTAMP(`datetime`) as voted_on FROM voters WHERE ip='$ip'") or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$unixtimestamp = $row['voted_on'];
echo $unixtimestamp;
}
Should work.应该管用。
First, I'd recommend against using datetime as a column name in mysql.首先,我建议不要在 mysql 中使用 datetime 作为列名。
If I had a DATETIME field called vote_time, I'd do it like this:如果我有一个名为 vote_time 的 DATETIME 字段,我会这样做:
SELECT UNIX_TIMESTAMP(vote_time) AS unix_vote_time FROM voters WHERE ip='$ip'
Then you'd access it via然后你可以通过
$unixtimestamp = $row['unix_vote_time'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.