Masroor_Shah Masroor_Shah - 1 year ago 67
PHP Question

Character Wise Advance search in AJAX and PHP?

I have done advance search which match character from front side. I want that it should match with middle and End of the word also or to everywhere in Database. How should i can d that my advance search code is here
PHP code........................

<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>
table {
width: 100%;
border-collapse: collapse;

table, td, th {
border: 1px solid black;
padding: 5px;

th {text-align: left;}

if (!$conn) {
die('Could not connect: ' . mysqli_error($conn));

echo "Data Error";

$sql="select name, id , age, sex from name where name like '$in%' or sex like '$in%' or age like '$in%' or id like '$in%'";
echo "<table>
while( $row = mysql_fetch_assoc( $display ) ){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['sex'] . "</td>";
echo "</tr>";
echo "</table>";


JS code

<!doctype html>
<meta charset="utf-8">
<title>Untitled Document</title>
function user(str){
document.getElementById("userhint").innerHTML = "";
else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("userhint").innerHTML = xmlhttp.responseText;
}"GET", "advanceSearch.php?q="+str, true);



<input type="text" onkeyup="user(this.value);" name="username" />
<br />
<div id="userhint"><b>User info will be listed here...</b></div>

Answer Source

done by little change in query

$sql="select name, id , age, sex from name where name like '%$in%' or sex like '$%in%' or age like '%%$in%' or id like '%$in%'";

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download