title: PHP Select between two strings
body: <p>I've the following mysql table :</p>
  
  <p>Table Name : <code>items</code></p>
  
  <pre><code>item_no qty
  1l1000bk 1
  1l1020be 2
  1l900bk 12
  1l820be 19
  </code></pre>
  
  <p>After creating a <code>form</code> that submits to other page which contains the following PHP code:</p>
  
  <pre><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)&gt;0){
  $num6 = mysql_num_rows($result6);
  
  for($i=0;$i&lt;$num6;$i++){    
  
  $row6 = mysql_fetch_assoc($result6);
  echo $row6['item_no']."&lt;/br&gt;";
  }
  }
  </code></pre>
  
  <p>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 :</p>
  
  <pre><code>1l900bk
  1l820be
  1l1020be
  1l1000bk
  </code></pre>
  
  <p>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?</p>
  
  <p>Please Help !</p>