Jump to content


Photo

Can you populate the <SELECT> list from a database?


  • Please log in to reply
2 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 18 September 2006 - 11:08 PM

I just need to know if this can be done. I have a contact form that is asking for a 'referrer' selection (who referred you) to be a dropdown menu. What i'd like to do is to generate the selections in that list from the member's list in the database instead of hard-coding it into the form each time we add or lose member.

Another 'key' is that I need the referrer's ID # to pass as well so that reports can be created using the ID# as the search key. So, basically when the visitor selects from the member list to choose the referrer that referrer's name is entered into a new table along with their ID# and the person they referred to.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 18 September 2006 - 11:18 PM

Yes, it can. Query the member table and make the option values the memberID and display member name.

<option value = '$id' > $name </option>

Having selected the referrer you only need store the referrer's id in the new table and not the name. You can get the name by joining to the member table.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 19 September 2006 - 12:07 AM

Barand, as usual you rock.

I'll need to brush up on the 'Join' part of the database structures. I'm not at all familiar with how that works and how to construct it. You've mentioned it before in previous posts. Is there a PHPFreaks tutorial on it somewhere?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users