⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

populating a select/option form tag



BayingHound
  • profile picture
  • Member

Posted 06 June 2013 - 23:11 PM

I have toyed and toyed with this and I admit, I am a total noob.  Here's what I'm trying to do...

 

Pull a row out of a database and create a <select><option> populated with that row.  Complete code would be great.  I want to use this populated dropdown on several other forms.  Thanks in advance, you'd really be helping me out. 


davidoster
  • profile picture
  • Member

Posted 09 June 2013 - 04:38 AM

Hello [member=bayinghound].

I am a bit confused with what you ask.

If what you 'pull' from the db is a single row why do you need a select where a select gives you mulptiple options to choose from?

Nevertheless, except this minor detail, are you sure Grocery CRUD is the right option for you?

If you just need to populate a field of one table with values from another table then use the set_relation function.


BayingHound
  • profile picture
  • Member

Posted 10 June 2013 - 09:32 AM

Okay, for example, I have a report form for brewing beer.  Instead of having to type the type of malt used, I want to populate that drop down from a table storing the malts.

 

Perhpas it isn't the best option, but it is one of the fastest.  I'm still learning, it's been a very long time since I did anything PHP related, and that was years ago.


davidoster
  • profile picture
  • Member

Posted 10 June 2013 - 12:23 PM

Ok!

Grocery CRUD wise the best option is by using a set_relation.

So you build a very simple table (beers) with fields e.g. id,year,brand, description and fill with all the data you want and then you do something like this,

$crud->set_relation('type_of_beer', 'beers', '{year}/{brand}, {description}');

I hope this helps.