Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Problem populating a dropdown box with MySQL query results (PHP/MySQL)
  2. <?php
  3. $query = "SELECT * FROM units_tb WHERE user_id='$userid'";
  4. $result = mysql_query($query) or die (mysql_error());
  5. while($row = mysql_fetch_assoc($result)){
  6. $aa = "<option value='{$row['unit_id']}'>{$row['unit_code']}</option>";
  7. }
  8. ?>
  9. <select name="t_unit"><? echo $aa; ?></select>
  10.        
  11. $aa .= "<option value='{$row['unit_id']}'>{$row['unit_code']}</option>";
  12.        
  13. <?php
  14. $query = "SELECT * FROM units_tb WHERE user_id='$userid'";
  15. $result = mysql_query($query) or die (mysql_error());
  16. $options = "";
  17. while($row = mysql_fetch_assoc($result)){
  18.     $options .= "<option value='{$row['unit_id']}'>{$row['unit_code']}</option>";
  19. }
  20. ?>
  21. <select name="t_unit"><? echo $options; ?></select>