Posted By

tylerhall on 10/12/06


Tagged

database menu dropdown options


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

blakeb
hudge
romanos
jfherring
scottwf
jtunes
nb109
vali29
dantreacy
latavish


Get Dropdown Options From Database


 / Published in: PHP
 

  1. function get_options($table, $val, $text, $default = "", $where = "", $order = "")
  2. {
  3. global $db;
  4. if($where != "") $where = "WHERE $where";
  5. if($order != "") $order = "ORDER BY $order";
  6. $db->query("SELECT * FROM `$table` $where $order");
  7. while($row = mysql_fetch_array($db->result, MYSQL_ASSOC))
  8. {
  9. if($row[$val] == $default)
  10. $out .= "<option value=\"" . $row[$val] . "\" selected=\"selected\">" . $row[$text] . "</option>";
  11. else
  12. $out .= "<option value=\"" . $row[$val] . "\">" . $row[$text] . "</option>";
  13. }
  14. return $out;
  15. }

Report this snippet  

You need to login to post a comment.