Jump to content

custom search


probir

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.