probir Posted December 9, 2010 Share Posted December 9, 2010 hi i am new in here and php coding. i got the following code frm my friend for making a name, address, passout of student searching database. <?php // TAKE THE INFORMATION FROM FORM. $search = $_GET['search']; // IF THERE IS NOT A KEYWORD GIVE A MISTAKE. if (!$search) echo "You didn't enter a keyword."."$text Back to Search Again <a href=searchform.php>Search</a>"; else { echo "<td>You searched for: <strong>$search </strong></td>"; mysql_connect('sql servername','sql server username','password'); mysql_select_db('database name'); $id=@$_GET['id']; //QUERY IS THE CODE WHICH WILL MAKE THE SEARCH IN YOUR DATABASE. //I WROTE AN EXPLANATION ABOUT IT AFTER THE CODE. $query="SELECT * FROM searchform WHERE MATCH(Name, Address, Pass) AGAINST('%$search%' IN BOOLEAN MODE)"; $result1 = MySQL_query($query); if(!$result1) { echo MySQL_error()."<br>$query<br>"; } if(MySQL_num_rows($result1) > 0) { echo "<table width='480' align='center' border='1' cellspacing='0' cellpadding='0'>"; while($result2 = MySQL_fetch_array($result1)) { //A short description from category. $description = $result2['category']; $searchPosition = strpos($description, $search); $shortDescription = substr($description, $searchPosition, 150); // I added a link to results which will send the user to your display page. echo "<tr><td>Name</td><td>Address</td><td>Pass</td></tr>"; echo "<tr><td>{$result2['Name']}</td><td>{$result2['Address']}</td><td>{$result2['Pass']}</td></tr>"; } echo "</table>"; }else { echo "No Results were found.<br>"."$text Back to Search Again <a href=searchform.php>Search</a>"; }echo "<br>"; } ?> every thing is working fine as i wanted. my database structure is below |NAME||ADDRESS||YEAR| |ABC|abc|1980| |XYZ||xyz||1980| but there is a small problem of showing the output result. when i search with 1980 it show 4 column 1st column is showing NAME, ADDRESS, YEAR 2nd column is showing |ABC|abc|1980| again 3rd column is showing NAME, ADDRESS, YEAR 4th column is showing |XYZ||xyz||1980| how i solve to not showing every column the NAME, ADDRESS, YEAR (3rd column) Link to comment https://forums.phpfreaks.com/topic/221104-custom-search/ Share on other sites More sharing options...
OldWest Posted December 9, 2010 Share Posted December 9, 2010 maybe i missed something, but where is $text defined? Link to comment https://forums.phpfreaks.com/topic/221104-custom-search/#findComment-1144847 Share on other sites More sharing options...
probir Posted December 9, 2010 Author Share Posted December 9, 2010 i forget to give the searchform.php here it is.. and the $text define this form <form action="searchresult.php" method="get"> <div align="center"> <p> <input name="search" type="text" size="30"/> <input name="submit" type="submit" value="Search" /> </p> </div> </form> Link to comment https://forums.phpfreaks.com/topic/221104-custom-search/#findComment-1144888 Share on other sites More sharing options...
probir Posted December 10, 2010 Author Share Posted December 10, 2010 finally i have solved my problem myself with a simple tricks given from my friend. Link to comment https://forums.phpfreaks.com/topic/221104-custom-search/#findComment-1145215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.