Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search script

Status
Not open for further replies.

JamesCliff

Programmer
Feb 16, 2005
106
0
0
GB
Hi all,

Im creating a search script for my site.

I have multiple tables which all contain different fields. I want one search box which i can type a keyword or keywords into which is then passed to a query which will search all the tables and there columns and display any row with one of the keywords within it.

How can i do this?

Thanks

Jim
 
Not enough information.

What database are you using??? What format do the searchable fields have??? text??? number??? Do the searchable fields have only one string or are they long multistringed fileds??? So the search would have to a find a particualr string withing the field.

Basically this would be a query building question which would be better abswered in the MYSQL forum.
Or something of that nature. For the PHP bit,
it would just be a matter of capturing the value in the textbox when it is submitted using the $_REQUEST or the $_POST variable. and using it in the query.
 
ok well......

I would be searching the database "briskfire" and the following tables and fields within them:

brisk_content : pagename, linkname, title, content
brisk_downloads : pagename, linkname, title, description
brisk_downloads_url : dl_url, linkname, title, description

I dont know what to put as the WHERE statement in the SQL as id be searching all of those fields for the keyword(s) entered within the textbox.

Anyone help?

Thanks

Jim

 
Insufficient data for a meaningful answer. At minimum, you must supply the vendor of the myriad of database systems PHP supports.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
The type of database, you are using, not the name of the actual db.
Is it MYSQL, MSQL, ORACLE, Postgresql etc...
 
mysql database m8

Anyone ideas?

What moe info do you need? ill supply it.

Thanks

Jim
 
ok guys,

Ive made the following script:

Code:
<table width="100%" align="center">
  <tr> 
    <td width="80%" height="96" valign="top"><div align="center">
        <p>&nbsp; </p>
        <p><font color="#4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Search 
          Briskfire:</strong></font></p>
        <p>
		          <?php

if(isset($_POST['add']))
{

include("config/db.php");		  
		  
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

mysql_select_db($db) or die ("Unable to select database!");

$keywords = $_POST["keywords"];

echo '<br><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>Results from your search:<br><br><br><br><br></font>';

$query = "select * from brisk_content where content like '%$keywords%'";
$rslt = mysql_query($query);
while ($result = mysql_fetch_array($rslt))

	{

echo '<font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><a href="index.php?page=content&pagename=' . $result['pagename'] . '">' . $result['linkname'] . '</a></font><br><br>';

	}
	
echo '<br><font color="4C4C4C" size="1" face="Verdana, Arial, Helvetica, sans-serif"><br><br><a href="index.php?page=search">New Search</a><br><br><br><br></font>';

}
else
{

?>
		</p>
        <form method="POST" action="index.php?page=search">
          <p>
            <input style="height:14px" type="text" name="keywords">
          </p>
          <p><input style="height:20px" type="submit" name="add" id="add" value="Click to search"></p>
        </form>		
        <?php
}

?>
        <p>&nbsp; </p>
      </div></td>
  </tr>
</table>

This successfully allows me to use the words entered into the textbox to search for matches or near matches in the brisk_content mysql table where content matches what is in the textbox.

However with the search above i want it to also search brisk_downloads_url table where the title = whats in the text box. Im not to sure howto go about this as i want what ever is entered into the textbox to be matched to both fields in both tables without the use of a listbox selecting which table and changing the WHERE clause between title and content depending on which table is selected in the listbox. I dont want this, i just want the keyword to go through both tables and be matched to title in the brisk_downloads_url table and content in the brisk_content table.

How would i go about altering the code above?

Thanks alot

Jim
 
how about this
Code:
$query = "select  * from brisk_content, brisk_downloads_url where brisk_content.content like '%$keywords%'" OR  brisk_downloads_url.title LIKE '%$kleywords%'

Notice the operator, "OR" this will tell it to bring back any records in either table that match the keyword.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top