> -----Original Message-----
> From: Burhan Khalid [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, November 01, 2003 11:16 AM
> To: Jake McHenry; [EMAIL PROTECTED]
> Subject: Re: [PHP] Array maybe? Or many SQL insert queries
> 
> 
> Jake McHenry wrote:
> >>-----Original Message-----
> >>From: Burhan Khalid [mailto:[EMAIL PROTECTED]
> >>Sent: Saturday, November 01, 2003 3:50 AM
> >>To: Jake McHenry; [EMAIL PROTECTED]
> >>Subject: Re: [PHP] Array maybe? Or many SQL insert queries
> >>
> >>
> >>Jake McHenry wrote:
> >>
> >>
> >>>Hi everyone, here's what I'm doing.
> >>>
> >>>As of right now, I don't have anything implemented, but
> >>
> >>here's what I
> >>
> >>>need to do.
> >>>
> >>>I have a web page, with a drop down list of hotels, an
> >>
> >>input box for
> >>
> >>>the users frequent hotel number, and a add button. At the bottom
> > 
> > of
> > 
> >>>the page is a update and continue button to move the user
> >>
> >>to the next
> >>
> >>>page with more options.
> >>>
> >>>What my boss wants is, when someone puts in a number, and
> >>
> >>clicks add,
> >>
> >>>he wants it to take that number and put it below the box,
> >>
> >>all on the
> >>
> >>>fly. I know I could do this through repeated sql insert
> >>
> >>querys, but I
> >>
> >>>was wondering if I could just put them into an array, then
> >>
> >>update the
> >>
> >>>database with one query after the user clicks the update
> >>
> >>and continue
> >>
> >>>button 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'd
> > 
> > 
> >>have 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
> >                                      ______________
> >                                     |______________| ADD
> > 
> > 
> >                              Submit and Continue      
> Submit and Exit
> > 
> > 
> > 
> > 
> > That'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.
> 
> 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
> 

I'm not making a drop down box, I just want the contents of what is
added to be displayed on the page.

I got all of this done by creating an array and storing it in a
session variable.

Here's the code...

if ($_POST['2_Add'] != "")
{
  if (($_POST['Frequent_Flyer_Program'] != "") &&
($_POST['Frequent_Flyer_Number'] != ""))
  {
    $array = array();
    $new =
"{$_POST['Frequent_Flyer_Program']},{$_POST['Frequent_Flyer_Number']}"
;
    $old = $_SESSION['Frequent_Flyer'];
    $array = array_merge($old, $new);
    $_SESSION['Frequent_Flyer'] = $array;
  }
  header("Location: profile2.php");
}



The only dilema I have now is... How can I allow the user to remove
entries from this array if they make a mistake?

On the other pages where the add button is, and the list, I have a
foreach loop that explodes the array and prints it out. Simple... Now
I just need a way for them to remove a certain entry.. Hopefully this
is an easy addition.

Thanks

Jake

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to