Jump to content

Search engine (Help)


Tauheed

Recommended Posts

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 by Tauheed
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...