Christiaan Posted November 4, 2012 Share Posted November 4, 2012 (edited) 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> Edited November 4, 2012 by Christiaan Quote Link to comment https://forums.phpfreaks.com/topic/270275-selecting-option-from-different-db_table/ Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2012 Share Posted November 4, 2012 (edited) 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"; Edited November 4, 2012 by Pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/270275-selecting-option-from-different-db_table/#findComment-1390113 Share on other sites More sharing options...
Christiaan Posted November 4, 2012 Author Share Posted November 4, 2012 (edited) 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. Edited November 4, 2012 by Christiaan Quote Link to comment https://forums.phpfreaks.com/topic/270275-selecting-option-from-different-db_table/#findComment-1390118 Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2012 Share Posted November 4, 2012 I don't see a database query anywhere in your code . . . Quote Link to comment https://forums.phpfreaks.com/topic/270275-selecting-option-from-different-db_table/#findComment-1390120 Share on other sites More sharing options...
Christiaan Posted November 4, 2012 Author Share Posted November 4, 2012 Okay. So what do I need to change in order to select the values from a database table? the table is called raf_lob, has the columns 'lob_id' and 'lob'. Quote Link to comment https://forums.phpfreaks.com/topic/270275-selecting-option-from-different-db_table/#findComment-1390122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.