Hi,
I want to find the highest value in a column 'jobref' in a table called 'jobs'
eg. SELECT MAX(jobref) FROM jobs
but how do I extract the value using PHP so I can print it to the screen?
You have two options, you can either use the [man]mysql_fetch_row[/man] function and reference the column by it's order in the resultset or you can alias the select expression using the AS keyword as explained in the MySQL select docs and then use either [man]mysql_fetch_row[/man], [man]mysql_fetch_array[/man], [man]mysql_fetch_assoc[/man] or [man]mysql_fetch_obj[/man].
that's great, thanks
actually you don't need to alias it. you can access it like this:
$sql = "SELECT MAX(jobref) FROM jobs "; $query = mysql_query($sql,$c); $result = mysql_fetch_array($query); $max = $result['MAX(jobref)'];