severndigital Posted July 17, 2007 Share Posted July 17, 2007 i am trying to find the max number entered into a field and i am having some difficulty. the query is quite basic, i thought here is my code <?php $getit = mysql_query("SELECT MAX(Mnum) FROM masters"); $workit = $getit + 1; echo $workit; ?> basically i want to find the MAX value and add 1 to it. the max value in this case is 300001 when i run this code however, $workit returns a value of 8. what am i doing wrong?? thanks in advance. chris Quote Link to comment https://forums.phpfreaks.com/topic/60385-solved-using-select-maxfield/ Share on other sites More sharing options...
akitchin Posted July 17, 2007 Share Posted July 17, 2007 mysql_query() does not return the actual result of your query. what it returns is a resource that POINTS to your results. you need to use an extraction function such as mysql_result() or mysql_fetch_assoc() to actually pull the results from that resource: $getit = mysql_query("SELECT MAX(Mnum) FROM masters"); $current_max_val = mysql_result($getit, 0, 0); $workit = $current_max_val + 1; echo $workit; check the manual for more info. Quote Link to comment https://forums.phpfreaks.com/topic/60385-solved-using-select-maxfield/#findComment-300406 Share on other sites More sharing options...
severndigital Posted July 17, 2007 Author Share Posted July 17, 2007 thanks for that. it is working fine now. thanks, again chris Quote Link to comment https://forums.phpfreaks.com/topic/60385-solved-using-select-maxfield/#findComment-300505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.