Xbox Mod Chip - Pontins - Remortgages - Loans - Online Image Resizer

PDA

View Full Version : Max() not working right...


Greenmethod
Sep 18th 2007, 3:38 pm
$highest_po_result = mysql_query("SELECT po_num FROM `inventory`");
$high_po = mysql_fetch_array($highest_po_result);
echo 'max: ' . max($high_po) . '<br>';
echo 'num rows: ' . mysql_num_rows($highest_po_result) . '<br>';
if (0 == mysql_num_rows($highest_po_result)){
echo 'newpo';
$new_po = 1;
}
else {
$new_po = max($high_po);
$new_po = $new_po+1;
}

I have the exact code written on another page and it works fine, but this just gives me max is 1 and num_rows is the actual number of rows every time.

I don't know what else I can do to troubleshoot.. any ideas?

nico_swd
Sep 18th 2007, 8:06 pm
What exactly are you trying to accomplish?

You know that you're working with just one single row from the database, right?



Are you trying to fetch the highest "po_num" from this table? Maybe you sould consider something like this:

SELECT po_num FROM `inventory` ORDER BY po_num DESC LIMIT 1

omgitsfletch
Sep 18th 2007, 10:59 pm
And if you still need the number of items:

SELECT COUNT(*) FROM `inventory`