我遇到以下 php/sql 问题。我在 mysql 终端中运行了 sql,它运行得很好。我还尝试了连接语句来警告一个字符串,并且在连接到数据库时成功地警告了该字符串。此代码中存在一些错误,当它应该返回两个整数时却返回 null。有什么建议吗?
$xmax = mysql_fetch_row(mysql_query('SELECT MAX(x) AS xmax FROM headerfooter WHERE site = "Brighter_Vista" AND location = 0'));
$xmax = $xmax['xmax'];
$ymax = mysql_fetch_row(mysql_query('SELECT MAX(y) AS ymax FROM headerfooter WHERE site = "Brighter_Vista" AND location = 0'));
$ymax = $ymax['ymax'];
echo '<script>alert("'.$xmax.$ymax.'")</script>';
最佳答案
我们看不到您的其余代码,但是,您可以将其细化为一个查询,执行以下操作:
$connection = mysql_connect(
$DB_hostname,
$DB_username,
$DB_password) or die(mysql_error());
mysql_select_db($DB_name, $connection);
$query = mysql_query("
SELECT MAX(x) AS xmax, MAX(y) AS ymax
FROM headerfooter
WHERE site = 'Brighter_Vista' AND location = '0'
", $connection) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
$xmax = $row['xmax'];
$ymax = $row['ymax'];
}
echo '<script>alert("'.$xmax.$ymax.'")</script>';
但是,如果您有时间、能力并且希望学习,您应该(正如其他人指出的那样)查看并使用 mysqli或PDO 。明智的建议,及时您就会明白原因。
关于php mysql 没有返回所需的整数,简单错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13485245/