I've the following mysql table :
Table Name : items
item_no qty
1l1000bk 1
1l1020be 2
1l900bk 12
1l820be 19
After creating a form
that submits to other page which contains the following PHP code:
$from = $_POST['from'];
$to = $_POST['to'];
$length = max(strlen($from), strlen($to));
$query6 = "SELECT * FROM items WHERE SUBSTRING(item_no, 1, ".$length.") BETWEEN '".$from."' AND '".$to."' ORDER BY item_no Desc";
$result6 = mysql_query($query6);
if(!$result6){
mysqli_error();
exit();
}
if(mysql_num_rows($result6)>0){
$num6 = mysql_num_rows($result6);
for($i=0;$i<$num6;$i++){
$row6 = mysql_fetch_assoc($result6);
echo $row6['item_no']."</br>";
}
}
The output is completely wrong, accoring to the select statment..I need to output the searched item_no as Descending order !.. Here what it shows :
1l900bk
1l820be
1l1020be
1l1000bk
How come 1l1000 is smaller than 1l900 ? It seems that it only compares the 3rd character ?..How to make sure it compares the full string?
Please Help !