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

Select and Display

Status
Not open for further replies.

neoJato

Programmer
Feb 24, 2005
5
US
I am trying to create a search for my website and I am running into some troubles...

I have the search field (where the user enters the text to search for)...and then below I have a drop-down option box with different options of way to display the results...

The problem I have is that when the search is made I can't seem to figure out how to pull which option they selected and 'echo' the order of results for that choice...???

I have four differnt choices for them to choose from...

When I just tell it to echo out a certian order, it works fine...I haved tried 'if' statments but it obviosuly didn't work...
 
Any code? It's hard to advise you without seeing some of your code.
 
//This is the drop-down option box
<form>
<select size="1" name="choice">
<option value="first">First</option>
<option value="second">Second</option>
<option value="third">Third</option>
<option value="fourth">Fourth</option>
</select>
</form>

//Below is similar to how i want the results to display
foreach ($result['resultElements'] as $r)
{
if ('first' == SELECTED)
{
echo "<br />";
echo "<li>Title: ... " . $r['title'];
echo "<br />";
echo "<li>Snippet: ... " . $r['snippet'];
echo "<br />";
echo "<li>URL: ... " . "<a href=" . $r['URL'] . ">" . $r['URL'] . "</a>";
echo "<br />";
echo "<li>Cache Size: ... " . $r['cachedSize'];
echo "<br />";
}
//etc. for the other three only it will echo the result in differnt orders
 
i think it would work better if your if statement were:

Code:
if ($_REQUEST['choice'] === "first") 
{
 do things; 
}

note you can replace REQUEST with POST or GET depending on the method of the sending form.

i don't thing the foreach works and would advise removing that loop unless you are creating the $result array somewhere further up the code.
 
I tried the above example (jpadie) and I'm still having issues...

below is a little more of the above code (using the last example)

<?
if (is_array($result['resultElements']))
{
foreach ($result['resultElements'] as $r)
{
if ($_POST['choice'] == "first")
{
do something;
}
else if ($_POST['choice'] == "second")
{
do something;
}
}
}
?>

Basically what i need is when an option is choosen from the form (third post) it will then see which one is selected and 'echo' out results specific to that choice...

My code searches just fine (has a result counter) but it wont display the results (Google like) when I try and make it to were the user has to select one of the four display options...
 
WHat does print_r($_POST) yield?
Are the choices posted correctly?
 
What do you mean by "are the choices posted correctly"??

print_r($_POST) yields:

Array ( [q] => 'searchQuery' ) //searchQuery is the text that was searched for

displays this ten (10) times (results limited to ten max)
 
Thx for all of the above help...

figured out my problem though...I was looking in the wrong place...
 
One of the most important debugging techniques is to inspect if the values you assume are there are actually present. The print_r($_POST) should also have shown the choice from the <select> element in the form.
Glad you resolved the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top