Getting array from database, displaying values in inputs |
[eluser]dallen33[/eluser]
I've been fiddling with this all day and can't figure it out. I have a form that you can enter email address in. Right now, there are 3 fields to enter the emails into. However, the administrator of the site can determine how many emails can be entered by changing a value in a config file. So the form for entering emails is displayed like this: Code: <?php Code: $contacts = ''; Here's the problem. I want to display these on page in <input>s. Now, the amount of inputs would have to be based on the config amount. But there can be empty fields, so if someone only submits one email, you still get three inputs but only one is full. What I'm doing right now is building a function called get_contacts: Code: function get_contacts($id) Then on the page where I want to display the contacts, I do this: Code: $contacts = $this->booking->get_contacts($ad_row->id); The problem I have is that an input is only displayed for each contact. But I want there to be 3 (or whatever the amount) input fields, even if only one or two is filled. I can't figure out how to do this. I tried for loops but it ended up looping the array value. Anyone have any idea? I'm lost!
[eluser]crikey[/eluser]
Hi GodsHand, What I'd do is loop through the number of contacts (based on the config value), and then for each iteration: if the contacts array isn't empty use array_shift to grab the next value, otherwise set the value to '', and print your input field with the value. Sorry, no pseudocode because I'm pressed for time, but that's the idea. EDIT: Oops, what I meant was loop through the input fields required, based on the config value.
[eluser]rameners[/eluser]
You can try it by hard-coding the limit. e.g... IMO Code: for (i=0; i < 3; i++)
[eluser]dallen33[/eluser]
I figured it out, so thought I'd post my solution incase it can help someone! Thanks for your help guys! Code: if ($contacts): |
Welcome Guest, Not a member yet? Register Sign In |