Tauheed 0 Posted April 4, 2013 Report Share Posted April 4, 2013 (edited) I have created a search engine to find records which are added in mysql database, whenever i will enter customer id to find record all records appear, suppose a customer id is 1 and when i will enter 1 then data of 11,12,13,....21,31,101 etc also appear on my page, both pages source code are mentioned below. please help me i m in deep trouble. i will be thankful for this kindness. index.php <html><head> <title>Search</title> </head><body> <form action="search.php" method="GET"> <input type="text" name="query" /> <input type="submit" value="Search" /> </form></body></html> -------------------------------------------------------------------------------------search.php <?php mysql_connect("localhost", "root", "root") or die("Error connecting todatabase: ".mysql_error()); mysql_select_db("mysql") or die(mysql_error()); ?><html><head> <title>Search results</title> </head><body><?php $query = $_GET['query']; $min_length = 1; if(strlen($query) >= $min_length){ $query = htmlspecialchars($query); $query = mysql_real_escape_string($query); $raw_results = mysql_query("SELECT * FROM result WHERE (`rollno` LIKE '%".$query."%')") or die(mysql_error()); if(mysql_num_rows($raw_results) > 0){ echo "<table border='1'><tr><th><h2>Roll No</h2></th><th><h2>Student Name</h2></th><th><h2>Marks Obtained</h2></th><th><h2>Remarks</h2></th></tr>"; while($results = mysql_fetch_array($raw_results)){ echo "<tr>"; echo "<td> <h3><center>" . $results['rollno'] . "</td></h3></center>"; echo "<td><h3>" . $results['name'] . "</td></h3>"; echo "<td><h3><center>" . $results['marks'] . "</td></h3></center>"; echo "<td><h3><center>" . $results['remarks'] . "</td></h3></center>"; echo "</tr>"; }echo "</table>"; } else{ echo "No results"; } } else{ echo "Minimum length is ".$min_length; } ?></body></html> Edited April 5, 2013 by Tauheed Quote Link to post Share on other sites
Ingolme 1,019 Posted April 4, 2013 Report Share Posted April 4, 2013 In your SQL query you need to add "WHERE customer_id=1" Quote Link to post Share on other sites
Tauheed 0 Posted April 5, 2013 Author Report Share Posted April 5, 2013 In your SQL query you need to add "WHERE customer_id=1"Dear then if i want to search an other record suppose 5,6 etc then? it is complete mysql search engine, for seaching every record it is not possible to change customer id every time.i just wanna to say whenever i will enter keyword in search box then required record should be appear on the page. but now whenver i will enter keyword in search box suppose 1, every reocrd have 1 (1,11,12,13...21,31,41,91,101 etc) that will appear and if i will enter 2 every records have 2 (2,12,20,21...32,42,92,102 etc) that will appear, i mean when i will enter 1 in search box then that recrod id is 1 should be appear. please help me, i will be thankful for this kindness. Quote Link to post Share on other sites
Ingolme 1,019 Posted April 5, 2013 Report Share Posted April 5, 2013 It seems I misunderstood your question. I think I know what you want now. The problem is a result of using the LIKE operator. Instead of (`rollno` LIKE '%".$query."%')" use `rollno` = $query Quote Link to post Share on other sites
Tauheed 0 Posted April 5, 2013 Author Report Share Posted April 5, 2013 Thank you sir, now it is working. once again a lots of thanks, you resolve this matter. Thank you very much Quote Link to post Share on other sites
Tauheed 0 Posted April 8, 2013 Author Report Share Posted April 8, 2013 Dear sir, i need some more help about my search engine, i just want that my search result should show in first page, i mean without loading. Some 1 told it is possible with the help of ajax, but i dont have any idea about ajax. Please help me i will be thanlful, my both pages source codes are mentioned above. Quote Link to post Share on other sites
Tauheed 0 Posted April 8, 2013 Author Report Share Posted April 8, 2013 Dear sir, i need some more help about my search engine, i just want that my search result should show in first page, i mean without loading. Some 1 told it is possible with the help of ajax, but i dont have any idea about ajax. Please help me i will be thanlful, my both pages source codes are mentioned above. Quote Link to post Share on other sites
Tauheed 0 Posted April 8, 2013 Author Report Share Posted April 8, 2013 Dear sir, i need some more help about my search engine, i just want that my search result should show in first page, i mean without loading. Some 1 told it is possible with the help of ajax, but i dont have any idea about ajax. Please help me i will be thanlful, my both pages source codes are mentioned above. Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 8, 2013 Report Share Posted April 8, 2013 There's a basic tutorial about ajax here: http://www.w3schools.com/ajax/default.asp If you do some research online you'll find plenty of additional information about what it is and how to use it. A library like jQuery would help you set things up quicker than doing everything yourself, but you should still know the technical details. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.