这是我使用的代码:
<?php
$hostname = "localhost";
$user = "user";
$pass = "password";
$database = "db";
$conn = @mysql_connect("$hostname","$user","$pass");
$chars="SET CHARACTER SET utf8"; mysql_query($chars);
@mysql_select_db($database);
$date = time();
$rand = mysql_query("SELECT * FROM `468x60ads` WHERE data+$expire>$date ORDER BY RAND() LIMIT 0,1") or die(mysql_error());
if(mysql_num_rows($rand) == 0)
{
echo "$zero";
}
else
{
while($row = mysql_fetch_assoc($rand))
{
echo "<center><a href='$row[link468x60]' target='_blank'><img src='$row[banner468x60]' width='468' height='60' style='border: 0px' alt=''/></a></center>";
}
}
?>
这是sql表:
CREATE TABLE IF NOT EXISTS `468x60ads` (
`id` int(12) NOT NULL auto_increment,
`banner468x60` text NOT NULL,
`link468x60` text NOT NULL,
`data` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=71 ;
这是我得到的错误:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行附近的'&gt; 1484246311 ORDER BY RAND()LIMIT 0,1'附近使用正确的语法
告诉我如何修复它。
答案 0 :(得分:0)
我忘了定义$ expire 我定义了它,现在它工作正常。