Jump to content

Selecting Option From Different Db_Table


Christiaan

Recommended Posts

Hello all.

 

I have a registration form. For the line of business I need to select the option from a dropdown which is stored in a (different) table. No rocket-science I would think. But my little script-snippet (see below) only returns a parse-error:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/deb13456/domains/c-create.net/public_html/fldrx/fldry/register.php on line 54

 

I've been trying to fix this, but unfortunately to no avail so far. Maybe a fresh pair of eyes can point me in the right direction. The main problem is (I think) is that the script is not looking in the correct database table, but where (and how) to put the reference to the table?

 

 

<?php
$arLob = array();
$arLob['lob_a'] = 'lob_a';
$arLob['lob_b'] = 'lob_b';
$arLob['lob_c'] = 'lob_c';
$arLob['lob_d'] = 'lob_d';

// store account id from db here
$lob_id = $row['lob'];

?>
<select name="lob" id="lob">
<?php
foreach($arLob as $key => $lob){
?>
<option value="<?php echo $key?>" <?php echo $lob_id==$key ? 'selected' : null?>><?php echo $Line of business></option>
<?php
}

?>
</select>

You need to use an editor with syntax highlighting. That would have made the problem clear:

<?php echo $Line of business></option>

<?php

 

At any rate, there's no real reason to jump in and out of php so much for something like this.

 

<?php
$arLob = array();
$arLob['lob_a'] = 'lob_a';
$arLob['lob_b'] = 'lob_b';
$arLob['lob_c'] = 'lob_c';
$arLob['lob_d'] = 'lob_d';

// store account id from db here
$lob_id = $row['lob'];

echo "<select name=\"lob\" id=\"lob\">\n";
foreach($arLob as $key => $lob){
   $selected = $lob_id == $key ? ' selected="selected"' : '';
   echo "<option value=\"$key\"$selected>$lob</option>\n";
}
echo "<select>\n";

Thanks Pikachu.

 

This does display a dropdown, but only with the values entered in the array. (lob_a- lob_d) and NOT the values that are stored in the database table raf_lob.

So this result is the same as an html <select> <option> </option> </select> tag.

In the table I have the actual names of the lob's, which needs to be displayed in the dropdown accordingly.

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.