here is my code and iam not able to do search in that.only the first search box list the data and when i given second search option both results wont come any idea
//this is my html code

        <script>
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
       xmlhttp.open("GET","getuser.php?q="+str+"&&k="+str,true);

        xmlhttp.send();
    }
}
</script>

<form>
<select name="users" onchange="showUser(this.value)">
  <option value="">Select Class:</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
   <option value="1">5</option>
  <option value="2">6</option>
  <option value="3">7</option>
  <option value="4">8</option>
   <option value="1">9</option>
  <option value="2">10</option>
  <option value="3">+1</option>
  <option value="4">+2</option>
  </select>
  <select name="users" onchange="showUser(this.value)">
            <option value="">Division</option>
            <option value="A">A</option>
            <option value="B">B</option>
            <option value="C">C</option>
            <option value="D">D</option>
            <option value="E">E</option>
            <option value="F">F</option>
            <option value="G">G</option>
            <option value="H">H</option>
            <option value="I">I</option>
            <option value="J">J</option>
            <option value="K">K</option>
            <option value="L">L</option>
            <option value="M">M</option>
            <option value="N">N</option>
                                                  </select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>









          <!-- Default box -->














// this is my getuser.php 



<!DOCTYPE html> <html> <head> <style>
table {
    width: 100%;
    border-collapse: collapse;
}

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

th {text-align: left;}
</style> </head> <body> <th> <a href="editschoolentry.php?classs=<?php echo $row['classs'];?>">Edit</a> </th> <th> <a href="deleteschoolentry.php">Delete</a> </th> <th> <a href="logout.php">logout</a> </th> <?php
if(isset($_POST['update']))
{
    include "edit.php";
}
$q = intval($_GET['q']);
$k= intval($_GET['k']);
$con = mysqli_connect('localhost','root','');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"shamsu");




$sql="SELECT * FROM schoolentry WHERE classs =".$q." and division = ".$k."";
$result = mysqli_query($con,$sql);

echo "<table> <tr> <th>Image</th> <th>Student Name</th> <th>Admission No</th> <th>Parent Name</th> <th>Classs</th> <th>Division</th> <th>Address1</th> <th>Address2</th> <th>Address3</th> <th>Address4</th> <th>Pincode</th> <th>Phone No</th> <th>DOB</th> <th>Adhar No</th> <th>Blood Group</th> <th>Mobile No</th> <th>Edit</th> <th>Delete</th> </tr>";

while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<form action=edit.php method=POST>";
    echo "<td>" . $row['image'] . "</td>";

    echo "<td>" . $row['student_name'] . "</td>";
    echo "<td>" . $row['admission_no'] . "</td>";
    echo "<td>" . $row['parent_name'] . "</td>";
    echo "<td>" . $row['classs'] . "</td>";
    echo "<td>" . $row['division'] . "</td>";
    echo "<td>" . $row['p_address'] . "</td>";
    echo "<td>" . $row['p_address1'] . "</td>";
    echo "<td>" . $row['p_address2'] . "</td>";
    echo "<td>" . $row['p_address3'] . "</td>";
    echo "<td>" . $row['p_address4'] . "</td>";
    echo "<td>" . $row['p_address5'] . "</td>";
    echo "<td>" . $row['dob'] . "</td>";
    echo "<td>" . $row['adhar_no'] . "</td>";
    echo "<td>" . $row['blood_group'] . "</td>";
    echo "<td>" . $row['mobile_no'] . "</td>";

    echo "</tr>";
}

echo "</table>";
mysqli_close($con);
?> </body> </html> 

Recommended Answers

All 9 Replies

Member Avatar for diafol
xmlhttp.open("GET","getuser.php?q="+str+"&&k="+str,true);

You should have

xmlhttp.open("GET","getuser.php?q="+str+"&k="+str,true);

Please tell me that you have a <head> and that you've just randomly decided to show the end of the page and not the start.

Also, please, PLEASE, indent your code properly and only put a neccessary amount of gap lines in to keep it readable. Frankly, your code is making my eyes bleed.

In regards to your problem: "results wont come" isn't best helpful and doesn't really match your title. Provide an accuracte description of what you have got, including error messages, and what you're not getting that you need. Screenshots always useful as well.

kk..from now onwards i will put exactly how you mean...

now my problem is at here...
$sql="SELECT * FROM schoolentry WHERE classs =".$q." and division = ".$k."";
//if i didnt gave division its working and if i choose division its not working

this is my getuser.php

<!DOCTYPE html>
<html>
<head>
<style>
table {
    width: 100%;
    border-collapse: collapse;
}

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

th {text-align: left;}
</style>
</head>
<body>
<th>
<a href="editschoolentry.php?classs=<?php echo $row['classs'];?>">Edit</a> 
</th>
<th>
<a href="deleteschoolentry.php">Delete</a> 
</th>
<th>
<a href="logout.php">logout</a> 
</th>
<?php
if(isset($_POST['update']))
{
    include "edit.php";
}
$q = intval($_GET['q']);
$k= intval($_GET['k']);
$con = mysqli_connect('localhost','root','');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"shamsu");
$sql="SELECT * FROM schoolentry WHERE classs =".$q." and division =' ".$k."'";
$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>Image</th>
<th>Student Name</th>
<th>Admission No</th>
<th>Parent Name</th>
<th>Classs</th>
<th>Division</th>
<th>Address1</th>
<th>Address2</th>
<th>Address3</th>
<th>Address4</th>
<th>Pincode</th>
<th>Phone No</th>
<th>DOB</th>
<th>Adhar No</th>
<th>Blood Group</th>
<th>Mobile No</th>
<th>Edit</th>
<th>Delete</th>


</tr>";

while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<form action=edit.php method=POST>";
    echo "<td>" . $row['image'] . "</td>";

    echo "<td>" . $row['student_name'] . "</td>";
    echo "<td>" . $row['admission_no'] . "</td>";
    echo "<td>" . $row['parent_name'] . "</td>";
    echo "<td>" . $row['classs'] . "</td>";
    echo "<td>" . $row['division'] . "</td>";
    echo "<td>" . $row['p_address'] . "</td>";
    echo "<td>" . $row['p_address1'] . "</td>";
    echo "<td>" . $row['p_address2'] . "</td>";
    echo "<td>" . $row['p_address3'] . "</td>";
    echo "<td>" . $row['p_address4'] . "</td>";
    echo "<td>" . $row['p_address5'] . "</td>";
    echo "<td>" . $row['dob'] . "</td>";
    echo "<td>" . $row['adhar_no'] . "</td>";
    echo "<td>" . $row['blood_group'] . "</td>";
    echo "<td>" . $row['mobile_no'] . "</td>";

    echo "</tr>";
}

echo "</table>";
mysqli_close($con);
?>

</body>
</html>

did you try removing an extra space in the query below -

$sql="SELECT * FROM schoolentry WHERE classs =".$q." and division =' ".$k."'";

should have been -

$sql="SELECT * FROM schoolentry WHERE classs =".$q." and division ='".$k."'";
Member Avatar for diafol

If you are using integers, no need to quote the vars. Additionally, you shoud be using prepared statements and build a dynamic where clause, depending on the get variables passed.

now also its not w orking..the division was not an integer thats y i had given like that

Member Avatar for diafol

now also its not w orking..the division was not an integer thats y i had given like that

Make up your mind. Is division an integer or not? Your code says it is and now you say it's not. Your code (line 108):

$k= intval($_GET['k']);

If it's not working, be specific with what's happening. We do not have access to your site/DB - no crystal ball. Help yourself by being less cryptic. It should not be a secret that we have to drag out of you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.