views:

193

answers:

2

I have a PHP registration that calls a mysql db for a dropdown box. No worries, it works fine. What I can't figure out though is this:

The box HAS TO populate with a name, but the POST needs to go to an id field. What I mean is this:

REGISTRATION.PHP

function generate_business_selections($default = '')
{
 $output = '';
 $application =& application();
 $sql =& sql();
 $lang_col = $application->get_language(LANG_COLUMN);
 $query = "SELECT id, name_en, {$lang_col} FROM ".DB_DEFAULT_PREFIX."members WHERE profile_type='Business'";
 $results = $sql->query($query);
 $num_rows = $sql->num_rows(); $sql_counter = 0;
 while($num_rows>$sql_counter++)
 {
  $this_result = $sql->fetch(MYSQL_ASSOC,$results);
  $output .= "\t" . '<option value="'.$this_result["name_en"].'"'.($default==$this_result["name_en"] ? ' selected' : '').'>'.$this_result[$lang_col].'</option>' . "\n";
 }
 return $output;
}

REGISTRATIONCOMPLETE.PHP

 $member_array["linkedid"] = $application->clean_input('register_business_selection','trim');

This achieves pulling the name into the box, but what I need to know is how to return just the id to another field in the db. That field is comma delimitted numbers (I didn't design the db, so don't blame me for that one!). It needs to populate the field with the id of the named object. For sake of argument:

id = 2

name_en = Bob Jones

field to insert to = linkedid And this must be populated with the ID, not the name_en.

Gosh, that is so discombobulated. Hope it makes sense to someone! :)

Thanks!

+1  A: 

I think you want the person's ID to be your drop down list's value.

$output .= "\t" . '<option value="'.$this_result["id"].'"'.($default==$this_result["name_en"] ? ' selected' : '').'>'.$this_result[$lang_col].'</option>' . "\n";
Kit Menke
I want id to be the value posted back to the mysql db, but I don't want the id displayed in the dropdown. Im sorry this is so confusing. I hate this project. HA!
Andie J
If I understand you right I don't think it can be done, unless you encrypt the id somehow.
Meep3D
Thanks Meep...I think I was being too vague. Im amazed that Kit was pickin up what I putting down. I just need the value that the form returns to the db to be the id, not the name_en. Think we've got it figure out. Y'all are great!
Andie J
Haha I just threw it out there hoping it was what you were looking for. :)
Kit Menke
A: 

you want the following in your html output:

<option value="ID">display name</option>

display name will appear in the form but ID will be sent when the form is submitted.

I think Kit has the right code to do this.

Craig
This is a full function though, where the option value is written into the PHP, so wouldn't my HTML read: <select name="register_business_selection" class="input_field">Since I've already told PHP to execute the option, shouldn't the generated function perform this?
Andie J