ncurran217 Posted December 20, 2012 Share Posted December 20, 2012 I would like to have my option value a different column then the display part of the option. I would like the value part to be the column ForteID and the display part to be the Rep column of my SQL Query. Is this possible? <?php $serverName = 'SRB-Nick_Desktop\SQLEXPRESS'; $connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection = sqlsrv_connect($serverName, $connectionInfo); $query = ' SELECT ForteID, Rep FROM Reps ORDER BY Rep'; $result = sqlsrv_query($connection,$query); if (!$result) { $message = 'ERROR: ' . sqlsrv_errors(); return $message; } else { $i = 0; while ($i < sqlsrv_num_rows($result)) { $meta = sqlsrv_fetch($result, $i); echo '' . $meta->name . ''; $i = $i + 1; } echo '<select name="ForteID" id="ForteID">'; while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) { $count = count($row); $y = 0; while ($y < $count) { $c_row = current($row); echo '<option value="[color=#ff0000]' .$c_row. '[/color]";>[color=#00ff00]' .$c_row.'[/color]</option>'; next($row); $y = $y + 1; } } echo '</select>'; sqlsrv_free_stmt ($result); } sqlsrv_close( $connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/272233-php-to-select-different-column-for-option-value/ Share on other sites More sharing options...
Psycho Posted December 20, 2012 Share Posted December 20, 2012 $serverName = 'SRB-Nick_Desktop\SQLEXPRESS'; $connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456'); $connection = sqlsrv_connect($serverName, $connectionInfo); $query = "SELECT ForteID, Rep FROM Reps ORDER BY Rep"; $result = sqlsrv_query($connection,$query); if (!$result) { return 'ERROR: ' . sqlsrv_errors(); } echo "<select name='ForteID' id='ForteID'>\n"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { echo "<option value='{$row['ForteID']}'>{$row['Rep']}</option>\n"; } echo "</select>\n"; sqlsrv_free_stmt ($result); sqlsrv_close( $connection); Quote Link to comment https://forums.phpfreaks.com/topic/272233-php-to-select-different-column-for-option-value/#findComment-1400643 Share on other sites More sharing options...
ncurran217 Posted December 20, 2012 Author Share Posted December 20, 2012 Wow, thank you that is ALOT cleaner looking as well!!!! Quote Link to comment https://forums.phpfreaks.com/topic/272233-php-to-select-different-column-for-option-value/#findComment-1400647 Share on other sites More sharing options...
ncurran217 Posted December 20, 2012 Author Share Posted December 20, 2012 I thought you could do it that way, but I was missing something before and couldn't get it to work! Thanks again!!! Quote Link to comment https://forums.phpfreaks.com/topic/272233-php-to-select-different-column-for-option-value/#findComment-1400650 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.