<select name=group2 size=1> <option selected>Member</option> <option>Beta Tester</option> <option>3D Modeler</option> <option>Sound Technician</option> <option>Artist</option> <option>Webmaster</option> <option>Coder</option> <option>Mapper</option> <option>Skinner</option> <option>Story Writer</option> </select>and i want the bit saying selected to move depending on what the person set this too last time they changed their profile. How do i do this?
<option selected>meh!</option>
#1
Posted 22 December 2005 - 11:08 AM
#2
Posted 22 December 2005 - 11:13 AM
#4
Posted 22 December 2005 - 11:21 AM
$job = $profile['group2'] from that specific member after connecting with the database, something similar you did in the admin_form for the Hive, I think.
And then perhaps
if ($job == 'Coder') print "<option >Member</option> <option>Beta Tester</option> <option>3D Modeler</option> <option>Sound Technician</option> <option>Artist</option> <option>Webmaster</option> <option selected>Coder</option> <option>Mapper</option> <option>Skinner</option> <option>Story Writer</option>";Though I think a switch might be better in this case.
Remember though I'm still learning this stuff, so I don't know for sure if it'll work but it's worth a try I think.
#5 Guest_ImmoMan_*
Posted 22 December 2005 - 11:53 AM
#7
Posted 22 December 2005 - 02:06 PM
You should make an array of jobs, store the index of the selected job in the DB and do the index > text conversions in PHP.
Additionally, I suggest abstracting the form elements (and any other html blocks you use repetitively) into custom functions like $html->form_dropdown() and similar, so you have a constant html output structure throughout your project. I use such a helper class in my projects, simplifies the work a lot. (Or if you'd rather use premade classes instead of making your own, check out PEAR::QuickForm.)
With only a numeric index stored in the database, php can build such a dropdown pretty easily:
<?php /* generic dropdown building function */ function form_dropdown($name, $label='', $values = array(), $size = 1, $selindex = 0) { if (count($values) == 0) return ''; $ind = 0; $ret = "<label for='$name'>$label\n<select id='$name' name='$name' size='$size'>\n"; foreach ($values as $k => $v) { $sel = ($ind == $selindex) ? ' selected=\'selected\'' : ''; $ind++; $ret .= "<option value='$k'$sel>$v</option>\n"; } $ret .= '</select>\n</label>\n'; return $ret; } /* building an array of jobs, etc */ $jobs = array ( 'Member', 'Beta Tester', '3D Modeler', 'Sound Technician', 'Artist', 'Webmaster', 'Coder', 'Mapper', 'Skinner', 'Story Writer' ); $index = 1; // this will determine the index of a selected item. The first item in the dropdown is 0, the second one is 1, etc. You will want to set this to the value you got from the DB, most likely. echo form_dropdown('job', 'Select your job:', $jobs, 1, $index); ?>
And after they submit this form, you can just store intval($_REQUEST['job']) into the DB.
What's stopping you from migrating to Ares? We can't implement it unless you tell us!
ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum
#8
Posted 26 December 2005 - 12:06 AM
Note, this is untested code...
//What the job is. $job = $profile['group2']; //Turn it into an option. $option = '<option>' . $job . '</option>'; //Turn it into a selected option. $selected = '<option selected>' . $job . '</option>'; //Make an array of all possible jobs, as options. $selections = array( '<option>Member</option>', '<option>Beta Tester</option>', '<option>3D Modeler</option>', '<option>Sound Technician</option>', '<option>Artist</option>', '<option>Webmaster</option>', '<option>Coder</option>', '<option>Mapper</option>', '<option>Skinner</option>', '<option>Story Writer</option>' ); //Count them. $numselections = count($selections); //Display them. If the current indice has a value of the job as an option, it will be selected, otherwise it will simply be displayed as an option. for($i=0; $i<$numselections; $i++){ if($selections[$i] == $option) echo $selected; else echo $selections[$i]; }I think that should work.
Edited by DeathRay2K, 26 December 2005 - 03:30 AM.
#9
Posted 26 December 2005 - 01:39 AM
// I'm gonna use a similar way to d2k although the code // could be even simpler than that // Declare vars $job = $profile['group2']; $arr_jobs_output = array(); // Make the array with all the jobs names $arr_jobs = array('Member', 'Beta Tester', '3D Modeler', 'Sound Technician', 'Artist', 'Webmaster', 'Coder', 'Mapper', 'Skinner', 'Story Writer'); // Use foreach foreach ($arr_jobs as $v) { // This checks whether the current array value processed matches the job variable // The rest is kind of self explanatory if ($v == $job) { $foo = '<option>'; } else { $foo = '<option selected>'; } $arr_jobs_output[] = $foo . $v . '</option>'; }Styles are easily changed from the foo variable, instead of modifying an entire array.
ARGUMENT FROM CREATION, a.k.a. ARGUMENT FROM PERSONAL INCREDULITY (I)
(1) If evolution is false, then creationism is true, and therefore God exists.
(2) Evolution can't be true, since I lack the mental capacity to understand it; moreover, to accept its truth would cause me to be uncomfortable.
(3) Therefore, God exists.
#10
Posted 26 December 2005 - 05:04 AM
#11
Posted 26 December 2005 - 09:05 AM
http://www.w3.org/TR/xhtml1/#h-4.5
What's stopping you from migrating to Ares? We can't implement it unless you tell us!
ModEnc - C&C Modding Encyclopedia | Modders' Quote Database | Yet Another C&C Modding Forum
#12
Posted 26 December 2005 - 06:25 PM
ARGUMENT FROM CREATION, a.k.a. ARGUMENT FROM PERSONAL INCREDULITY (I)
(1) If evolution is false, then creationism is true, and therefore God exists.
(2) Evolution can't be true, since I lack the mental capacity to understand it; moreover, to accept its truth would cause me to be uncomfortable.
(3) Therefore, God exists.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users