• (2 Pages)
  • +
  • 1
  • 2

Populating a dropdown/Combo box from MySQL. How to get your database information into a dropdown box. Rate Topic: ***** 2 Votes

#16 Sashaca2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-September 12

Posted 14 September 2012 - 05:19 PM

View PostValek, on 21 March 2009 - 02:07 PM, said:

$dropdown = "<select name='users'>";
while($row = mysql_fetch_assoc($result)) {
  $dropdown .= "\r\n<option value='{$row['username']}'>{$row['username']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;


Is there a way to concatenate field name from my table within the <option> tags? In other words, I have a table with about 6 fields but I want to display three of them (per line) in a dropdown menu. I can't seem to figure out how/where to put different $row['field name'] elements to make them show up. I have the select query fine to pull them in, but can't display them to save my life. The field names are f_name l_name and paper and I would ideally like it to display : f_name l_name: paper.

Any help or advice would be appreciated! thank you!
Was This Post Helpful? 0
  • +
  • -

#17 cobbljock  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-February 14

Posted 27 February 2014 - 12:40 PM

Quote

nothing is being displayed in the combo box:S


I had this problem too, and it took me forever to figure it out. First, have you established a connection to the database you're trying to pull information from? If you have, then check your connection script. See if you are doing mysql_connect or mysqli_connect. This code uses mysql, and the problem I had was that I was using mysqli to connect. If you are using mysqli otherwise, simply change this part of his script:

while($row = mysql_fetch_assoc($result))

to this:

while($row = mysqli_fetch_assoc($result))

Your problem sounds exactly like the one I had, and it was this dumb little mistake that was messing it up. Hope this helps!
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2