the problem is that its an undifined varible ($last) intill i type the second word, i
if($_POST)
{
$q=$_POST['searchword'];
$q = explode(' ', $q);
$first = $q[0];
$last = $q[1];
$sql_res=mysqli_query($mysqli, "select * from dogs where firstname like '%$first%' and lastname like '%$last%' order by id LIMIT 5");
while($row=mysqli_fetch_array($sql_res))
{
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$MainImage=$row['MainImage'];
$country=$row['country'];
$id = $row['id'];
$re_fname ='<b>'.$first.'</b>';
$re_lname='<b>'.$last.'</b>';
$final_fname = str_ireplace($first, $re_fname, $firstname);
$final_lname = str_ireplace($last, $re_lname, $lastname);
echo '
<div style="position:relative;z-index:100000;">
<div class="display_box" style="display:block;" align="left">
<img src="image/'.$MainImage.'" style="width:50px; height:50px; float:left; margin-right:6px" />'.$final_fname.' '.$final_lname.'<br/>
<span style="font-size:9px; color:#999999">'. $country .'</span></div>
</div>
';
}
}
else
{
}
would like do somet like this....
$textFields = array('lastname', 'firstname');
$conditions = array();
foreach ($textFields as $field)
foreach ($q as $searchWord)
$conditions[] = "\n\t$field LIKE '%$searchWord%'";
$sql_res=mysqli_query($mysqli, 'SELECT * FROM dogs WHERE '.implode(' or ', $conditions).' order by id LIMIT 5');
there problem is i dont want to have a query like this....
$sql_res=mysqli_query($mysqli, "select * from dogs where firstname like '%$first%' and lastname like '%$first%' and firstname like $last AND $lastname like $last order by id LIMIT 5");
i want it like this....
$sql_res=mysqli_query($mysqli, "select * from dogs where firstname like '%$first%' and lastname like '%$last%' order by id LIMIT 5");
any help ill be happy :)