$etos = $_POST['txtYear']; $dash = strpos($etos, "-"); // this looks for the dash (-) in the $years variable if($dash !== false){ $start = substr($etos, 0, $dash); $end = substr($etos, $dash + 1); $array = range($start, $end); $sql = "select * from tbl_year"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ extract($row); if(in_array($year_name, $array)){ $year_table[] = $year_id; } } print_r($year_table); for($i=0; $i