Forum Moderators: coopster

Message Too Old, No Replies

Php script: passing query using value in the "option value="

         

Imaster

7:02 am on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could someone please provide me a php script for the following:

I have crawled various sub-domains of my site using a search engine which does not provide the option to search in any particular directory/sub-domain. I have an idea which if implemented could help me sort the problem.

Each sub-domain has been crawled in a different database and the url syntax for search is as follows:

[search.domain.com...]

Where keyword = any keyword searched
dbname = the name of the database

I have 10 different sub-domains and I was planning on implementing a search box with a dropdown list next to it.

Considering that one such sub-domain is for cars and the database for that is 'cars', someone wants to search for BMW in that particular sub-domain, he could simply enter the keyword "BMW" in the keyword box and select "Cars" for the dropdown list next to the keyword box which would search in the 'cars' database using the following query syntax:

[search.domain.com...]

The same goes for other databases/sub-domains as well.

In short, if he enters a keyword and selects any particular value from the dropdown list it would redirect him to the search results using the search query syntax defined for each option value.

<Option value="cars">Cars</option>
[search.domain.com...]

<Option value="pets">Pets</option>
[search.domain.com...]

<Option value="fl">Family Life</option>
[search.domain.com...]

I hope I have been clear in explaining this and look forward to hearing some solution to this. If possible, do provide me with the form code as well as php code.

TIA

wruk999

7:13 am on May 5, 2004 (gmt 0)

10+ Year Member



Hi Imaster,

Personaly, I would have the details stored in a database table - makes easy adding/editting/deleting as later date, without having to alter the code on the page.

Then, have the following on your page. This is presuming you have connected to your database with the relevant info,:


The PHP bit:

<?

// create SQL statement
$sql = "SELECT * FROM categories
ORDER BY name ASC";

// execute SQL query and get result
$sql_result = mysql_query($sql3)
or die("Couldn't execute query.");

// put data into drop-down list box
while ($row = mysql_fetch_array($sql_result)) {

$dbase_name = $row["dbase_name"];
$option = $row["option"];

$option_block .= "<OPTION value=\"$dbase_name\">$option</OPTION>";

}

?>

And then, whereever you want the drop-down list:


<SELECT name="database">
<? echo "$option_block";?>
</SELECT>

Store the database name value in the $dbase_name column (such as fl or cars) and store the value name in the $option column (such as Family Life or Cars)

Hope this helps,
wruk999

Imaster

8:15 am on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks wruk999,

I believe this would create php form but I also need to put the static form code for the search box with the dropdown list on all the html pages of my site.

Also, how would the redirection take place after entering the keyword and selecting a value from the dropdown list?

Apologies, but I am not well acquainted with PHP. I simply read tutorials and try to build things :)

wruk999

8:23 am on May 5, 2004 (gmt 0)

10+ Year Member



Hi Imaster,

If your search script is using GET variables, such as

[search.domain.com...]

Then, just set the method of the the form to be GET, and the action to: search.domain.com/search?
with the query text box called query and the dropdown select list called database.

Regarding having it on all html pages, are they php?
You could have a php include with the function on?
Without knowing how your site is setup, I wouldn't be able to comment further. The way I showed was to populate a drop-down list from entries in a database.

wruk999

Imaster

8:39 am on May 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi wruk999

Thanks. That makes a lot of sense and I believe it would work. All the pages on my site are html pages.

Thanks again for all your help.