will35010 Posted June 1, 2009 Share Posted June 1, 2009 I'm using this code to populate a select box. I want the names to show up as last name, first name and the dl field hidden. I want to use dl as the value since it will always be unique. Thanks. function getDrivers() { $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['fname']."\">".$row['lname']."\n "; } Quote Link to comment https://forums.phpfreaks.com/topic/160549-solved-phphtml-help/ Share on other sites More sharing options...
lonewolf217 Posted June 1, 2009 Share Posted June 1, 2009 <?php function getDrivers() { $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"$row['dl']\">".$row['lname'].",".$row['fname']."</option>"; } Quote Link to comment https://forums.phpfreaks.com/topic/160549-solved-phphtml-help/#findComment-847317 Share on other sites More sharing options...
Alex Posted June 1, 2009 Share Posted June 1, 2009 Well, if it's a function you want it to return, rather than echo.. right? function getDrivers() { $sql = "SELECT fname, lname, dl FROM drivers"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { $list .= '<option value="' . $row['dl'] . '">' . $row['lname'] . ', ' . $row['fname'] . '</option>'; } return $list; } Quote Link to comment https://forums.phpfreaks.com/topic/160549-solved-phphtml-help/#findComment-847320 Share on other sites More sharing options...
will35010 Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/160549-solved-phphtml-help/#findComment-847323 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.