We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

tylerhall on 10/12/06


Tagged

database menu dropdown options


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

blakeb
hudge
romanos
jfherring


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.