Question : Why do I get an incorrect number?

Given the code and database attached, I had expected to get a print out of "max_number: 10". Instead I get "max_number: 9". Can anyone of you gurus of MySQL explain that for me?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
<?php
error_reporting(E_ALL|E_STRICT); 
ini_set('display_errors', '1');
include "whatever/dbconfig.php";  
@mysql_connect($host,$usr,$pwd) or die("<p>No connection.</p>");  
@mysql_select_db($db) or die("<p>Cannot connect" . $db . ".</p>");   
$SQL = " SELECT MAX(number) as max_number FROM table WHERE date = '2010-09-04' AND place = 'Kranen'  AND number <= 29 ";
$ret = mysql_query($SQL);
if (!$ret) { echo(mysql_error()); }
else {
	while ($row = mysql_fetch_array($ret)) {
        $max_number  = $row["max_number"];
        
		 
		echo "max_number: $max_number";
	}}
?>
Attachments:
 
Print out of relevant part of database
Print out of relevant part of database
 

Answer : Why do I get an incorrect number?

your field "numberi" is very likely of data type varchar, in which MAX() will indeed return "9" and not "10"

change the field to numerical data type, and the order by as well as MAX will work on numerical comparison and not string comparison

you could also try:

MAX(yourfield + 0)
Random Solutions  
 
programming4us programming4us