I am having an issue with the following php/sql. I ran the sql in the mysql terminal and it worked perfectly. I also tried my connect statement alerting a string and it succesfully alert the string when connected to the db. There is some error within this code that is returning null when it should be returning two integers. Any suggestions?
$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>';
We can't see the rest of your code, but, you can refine this into one query, doing something like:
$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>';
However, if you have the time, ability and wish to learn, you should (as noted by others) look at and using either mysqli or PDO. Wise advice and in time you'll understand why.
The easist solution is to check if the sql statement is returning an error using:
mysql_query('SELECT MAX(y) AS ymax FROM headerfooter WHERE site = "Brighter_Vista" AND location = 0') or die('Error: '.mysql_error());
Side note: Don't use mysql_* functions anymore, that time has passed. Use either mysqli or PDO