[SOLVED]Getting max(column_value) into a PHP variable
Posted: Thu Jan 22, 2004 10:45 am
There is probably a very simple answer to this one but I have tried many versions and can't seem to get the value of the ID (auto_increment) column, the query runs ok but I can't get the value returned.
PHP and MySQL, heres the code I am using...
num_rows returns 1 but $item_ID is empty, I have also tried the following query...
but $item_ID still appears to be empty.
I am totally at a loss here, and I can't seem to find information that goes beond the query which makes me think it is getting the row that is the problem.
Thanks in advance

PHP and MySQL, heres the code I am using...
Code: Select all
<?php
$query="SELECT MAX(item_ID) AS item_ID FROM _account WHERE client = '$client' AND service='$service' LIMIT 1";
if (!mysql_query($query,$connection)) {
echo "Error $query";
exit;
} else {
if($num_rows == 1) {
$row = mysql_fetch_array($query_result);
$item_ID = $row["item_ID"];
echo "num_rows=$num_rows<br />item_ID=$item_ID";
}
}
?>Code: Select all
<?php
$query="SELECT MAX(item_ID) FROM _account WHERE client = '$client' AND service='$service' LIMIT 1";
?>I am totally at a loss here, and I can't seem to find information that goes beond the query which makes me think it is getting the row that is the problem.
Thanks in advance