Page 1 of 1

How to remember a selection?

Posted: Thu Jan 27, 2005 12:00 pm
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

Posted: Thu Jan 27, 2005 12:06 pm
by rehfeld
here would be a more functional example

http://codewalkers.com/seecode/507.html

Posted: Thu Jan 27, 2005 12:08 pm
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.

Posted: Thu Jan 27, 2005 12:28 pm
by lostboy
i wrote a function for this: here

Posted: Thu Jan 27, 2005 12:53 pm
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!)