Jump to content

PHP search help


influenceuk

Recommended Posts

Hi guys,

Really having some issues getting a search feature implemented onto my site.

 

Basically i am after a search which will search the database (2 tables) and display the results the user has searched for.

 

I have tried the codes from the library from PHP Freaks, yet had no luck. Can any one help me please?

Link to comment
Share on other sites

Maybe some code you wrote should help track the problem.

 

Normaly, for a basic search you should write something like:

$query = "SELECT * FROM table WHERE field LIKE '%$search%'";
$results = @mysql_query($query) or die();
while($values = mysql_fetch_array($results)){
     echo $values['column'];
}

where $search is the value retrieved from the input.

 

For searching your two tables you have a set of different possibilites. U can use 2 different queries:

$queryTable1 = "SELECT * FROM table1 WHERE column LIKE '%$search%'";
$queryTable2 = "SELECT * FROM table2 WHERE column LIKE '%$search%'";

Then you execute the query and get the data for each table.

 

If the tables columns are identical then u can use UNION between the two queries:

$query = "SELECT * FROM table1 WHERE column LIKE '%$search%' UNION SELECT * FROM table2 WHERE column LIKE '%$search%'"

 

If the case is different than i guess you must use the appropriate JOIN command but im not familiar with those so i cant say much. Hope i helped.

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.