Help making this Php function more efficient
Posted: Mon Mar 03, 2014 6:08 am
Hi every one i wnat to improve the output quality of this function.
1. how do i make the function work when the string length is greater than three, i tried using strlen()
also any other thing that will make this better.
thanks.
Code: Select all
if (isset($_POST['searchVal']) && trim($_POST['searchVal'])!='' && strlen('searchVal') > 3){
$searchq = $_POST['searchVal'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
//query
$query = mysql_query("SELECT * FROM authors WHERE name LIKE '%$searchq%'") or die("could not search");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'there was no search result!';
}else{
$output = '<ul ="dropdown">';
while($row = mysql_fetch_array($query)){
$output .= '<a class="searchresult" href="#"><li> '.$row['name'].'</li></a>';
}
$output .= '</ul>';
}
}
echo($output);
also any other thing that will make this better.
thanks.