$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; } PHP: 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?
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 Code (sql):