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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple search using php 2

Status
Not open for further replies.

IanNav

Programmer
Feb 26, 2001
79
Hi,


On my site i have 3 command buttons labelled Google, Yahoo & MSN.

With 1 'search' text box above.

I would like to be able to press either of the search buttons and for it to search from the single text box and then open a new window from that specific search.

Could you give me a hand in sorting this problem. I am using php.

Many thanks

Ian
 
something like this?
Code:
<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
<input type="text" name="srchbox" /><br/>
<input type="submit" name="submit" value="google" />&nbsp;
<input type="submit" name="submit" value="yahoo" />&nbsp;
<input type="submit" name="submit" value="msn" />
</form>

<? 
if (isset($_POST['submit'])):
 switch ($_GET['submit']):
  case "google":
    //do the google search
    break;
  case "yahoo":
   //do the yahoo search
   break;
  case "msn":
  //do the msn search
  break;
  default:
   //do nothing
 endswitch;
endif;
?>
 
I think the new window will have to be opened by the use of the 'target="..."' attribute of the form:

Here's a simple example.

Code:
<?php
$strings = array
(
	'Google' => '[URL unfurl="true"]http://www.google.com/search?q=',[/URL]
	'Yahoo' => '[URL unfurl="true"]http://search.yahoo.com/search?p=',[/URL]
	'MSN' => '[URL unfurl="true"]http://search.msn.com/results.aspx?q='[/URL]
);

if (isset ($_POST['submit_button']))
{
	$query = $strings[$_POST['submit_button']] . $_POST['search_string'];
	
	header ('Location: ' . $query);
}
else
{
	print '
<html><body>
<form method="post" action="test_window.php" target="_new">
<input type="text" name="search_string">
<input type="submit" value="Google" name="submit_button">
<input type="submit" value="Yahoo" name="submit_button">
<input type="submit" value="MSN" name="submit_button">
</form></body></html>';
}
?>


Want the best answers? Ask the best questions! TANSTAAFL!
 
Thanks guys. Magic! Just what i needed!

sleipnir214, i have used code based on your example, becuase i needed it to open in a new window.

Cheers

Ian

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top