Re: Array maybe? Or many SQL insert queries
| From: | Burhan Khalid | Date: | Sat, 01 Nov 2003 16:16:05 +0000 |
| Subject: | Re: Array maybe? Or many SQL insert queries | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168273@lists.php.net to get a copy of this message | ||
Jake McHenry wrote:
You can attach a javascript function to the onclick event of the Add button that populates your drop down. Of course, this assumes that you have a predefined array of all possible values (in javascript) that the user can enter. However, if your user can arbitrarily enter values, and all you need to do is "add" them to the drop down list, then some simple javascript DOM is all you need. Then when the user clicks on the Submit and Continue button, use php to read the dropdown array (appending [] to the name attribute's value will help -- like this <select name="foo[]"> then $_POST['foo'][0] would hold the value of your selected index). If you are not a big fan of javascript + DOM (this is, after all, a PHP list) -- you can use PHP to dynamically populate the dropdown by appending the value of the entered box to the array. Something along the lines of (untested): $textbx = isset($_POST['textbx']) ? $_POST['textbx'] : NULL; $menu = array(); if ($textbx != NULL) { $menu['somevalue'] = $textbx; } else { echo "<select name=\"chooser[]\"><option value=\"NULL\" selected=\"selected\">Please enter a value</option></select>"; } /* we now assume that the array was populated */ echo "<select name=\"chooser[]\">\n"; echo "<option value=\"NULL\" selected=\"selected\">Value Entered Below</option>\n"; while(list($k,$v) = each($menu)) { echo "<option value=\"".$k."\">".$v."</option>\n"; } echo "</select>"; Hope this helps. -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com-----Original Message----- From: Burhan Khalid [mailto:phplist@meidomus.com] Sent: Saturday, November 01, 2003 3:50 AM To: Jake McHenry; php-general@lists.php.net Subject: Re: [PHP] Array maybe? Or many SQL insert queries Jake McHenry wrote:ofHi everyone, here's what I'm doing. As of right now, I don't have anything implemented, buthere's what Ineed to do. I have a web page, with a drop down list of hotels, aninput box forthe users frequent hotel number, and a add button. At the bottomthe page is a update and continue button to move the userto the nextpage with more options. What my boss wants is, when someone puts in a number, andclicks add,he wants it to take that number and put it below the box,all on thefly. I know I could do this through repeated sql insertquerys, but Iwas wondering if I could just put them into an array, thenupdate thedatabase with one query after the user clicks the updateand continuebutton at the bottom, to get them to the next page?This sounds like something javascript can fix. If you can be a bit more precise "below the box" doesn't mean much. What box? Is it a big green box? Blue box? Box of boxes? If you want "on the fly" then its javascript. For php to work, you'dhave to send a request to the server, which would kill your "on the fly" part.I don't know why I said on the fly.. Lol.. The box I'm referring to is the input field box. I just need what's submitted via the input field and add button to show up in a list below the input box, to show the account numbers that were entered. I can either insert them into the database each time the add button is clicked, or my preference if possible, put them in an array of some kind then submit them all at once. To get a picture of what I want...:Site Logo ______________ |______________| ADDSubmit and Continue Submit and ExitThat's basically what this page looks like. What I need is when the person inputs the account number in the input box, and clicks add, it needs to refresh the page with the added number below that box, then again for each number they enter.