Jump to content

[SOLVED] EXplanation help


michaelk46

Recommended Posts

Hey all,

 

I am still fairly new to PHP programming and I am trying to put together a page where you select search terms from a drop down menu and it keeps the menu at your search choice in the menu after the search.

 

Here is the code I was suggested to use, but I am having problems understanding how it keeps the choice in the menu.

 

I can almost understand how it works, but I need a little push to grasp it.

 

Here is the code:

 

foreach($options as $key => $content)

        {

            if ($key == $value) $select = ' selected="selected"';

            else                $select = NULL;

            $html .=

                '<option value="' . htmlspecialchars($key) . '"' . $select .

                '>' . htmlspecialchars($content) . '</option>' . "\n";

        }

 

Now I understand how to walk through the code, but I am having trouble understanding how it holds over the choice.

 

THanks in advance for the help...

Link to comment
https://forums.phpfreaks.com/topic/177919-solved-explanation-help/
Share on other sites

It simply loops through the contents of the options array echo'ing them out. If the current item in the array matches $value (which must have been set further up the code using something like $value = $_POST['name_of_select_node']) it includes selected="selected" as part of the node. In HTML this basically means select this item in the list.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.