How to remember a selection?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Ice9
Forum Newbie
Posts: 4
Joined: Tue Jan 18, 2005 5:56 pm

How to remember a selection?

Post by Ice9 »

Hello guys and gals

Before I ask my question I want to say I am a php noob. :oops:

Okay, here is my problem:
I have 2 forms, form #1 contains the model selections, and form #2 contains view mode selections.

How to remember the choice made on the initial form, when selecting and reloading the following form?

I searched quite a bit on this matter, but the only thing I found was about how to remember the selection made, but with incremental numbers as selection.
Example:

Code: Select all

<?php 

$sel  = 1;
$qty = 6;

echo '<select name="selmod">';

while($sel <= $qty) &#123;
if($sel == $_POST&#1111;'selmod']) &#123;
echo "<option value='$sel' selected>$sel</option>";
&#125; else &#123;
echo "<option value='$sel'>$sel</option>";
&#125;
$sel++;
&#125;

echo '</select>';

?>
Somewhat an easy code, but I am witnessing the code, thus I understand it. But for my problem, I can't get an idea how to start the code; I need to do like the code above, except not with numbers, with individual text, which I presume will have a variable for each selection, and then what?

Any help is immense, thx!

Ice9
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

here would be a more functional example

http://codewalkers.com/seecode/507.html
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

creating a selection where the values are text instead of numbers works in much the same way.. typically you have a database query that drives the creation:

Code: Select all

$result = mysql_query(...) or die(mysql_error());
while($row = mysql_fetch_assoc($result))
  echo '<option value="' . $row&#1111;'field name'] . '">' . $row&#1111;'field name'] . '</option>' . "\n";
the selection made will be stored in the submitted data under the select's specific name.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

i wrote a function for this: here
User avatar
Ice9
Forum Newbie
Posts: 4
Joined: Tue Jan 18, 2005 5:56 pm

Post by Ice9 »

Thx for the input,
The codes mentioned in those links are a bit big for my noob eyes, but I will try to figure out how it works and what can be done with it. I'm very slow with these things...

Thank you again!

(Btw, nice forum!)
Post Reply