Guys

Just another challenge; i've taken the code of Wouter and as you can see i'm
first passing data to the reis table.. Then i retrieve the ID... But when
you have multiple selection's the trouble starts... The first record is o.k.
but then the second record Get's the ID of the first.. How to avoid this?

Frank

<?
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db) or die ("Unable to select database!");
$_POST["submit"]=isset($_POST["submit"])?$_POST["submit"]:"";
if($_POST['submit']!="")
{

$reisnaam=addslashes($_POST['reisnaam']);

$query3 = "INSERT INTO reis(reisnaam) VALUES ('$reisnaam')";
$result = mysql_query($query3) or die ("Error in query: $query. " .
mysql_error());
print_r($_POST);

if(is_array($_POST['somename'])) {
foreach($_POST['somename'] as $Key => $Value) {
$query = 'INSERT INTO ra(reisid, accid) VALUES (LAST_INSERT_ID(),
'.$Value.')';
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
};
} else {
$query = 'INSERT INTO ra(reisid, accid) VALUES (LAST_INSERT_ID(),
'.$_POST['somename'].')';
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());}
}
?>
<FORM method=post action=<? $_SERVER['PHP_SELF'] ?>>
<input size="70" maxlength="250" type="text" name="reisnaam"><br>
<SELECT name='somename[]' size=10 multiple id='somename[]'>
<OPTION value='1'>First Thingie</OPTION>
<OPTION value='2'>Second Thingie</OPTION>
<OPTION value='3'>Third Thingie</OPTION>
<OPTION value='4'>Fourth Thingie</OPTION>
<OPTION value='5'>Fifth Thingie</OPTION>
</SELECT>
<input type=submit name=submit value=Toevoegen>
</FORM>
----- Original Message ----- 
From: "Frank Keessen" <[EMAIL PROTECTED]>
To: "Jim Lucas" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, June 03, 2003 10:37 PM
Subject: Re: [PHP] Multi Selection


> Jim,
>
> Why does the data have to be reindexed??? I don't understand, can you give
> me an explenation?
>
> Thanks,
>
> Frank
> ----- Original Message ----- 
> From: "Jim Lucas" <[EMAIL PROTECTED]>
> To: "Frank Keessen" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, June 03, 2003 10:30 PM
> Subject: Re: [PHP] Multi Selection
>
>
> > I would look into doing something like this.
> >
> > The HTML code that Wouter will work just fine.  My ideas are for the
> process
> > page.
> >
> > When you insert data into a table, it has to re-index the table if you
> make
> > your statement insert all the data at one time it will only re-index the
> > table one time.
> >
> > It goes a little something like this.
> >
> > <?php
> > if(isset($_POST['somename'])) {
> >   print_r($_POST['somename']);
> >
> >   echo "<BR>";
> >
> >   foreach($_POST['somename'] AS $k => $v) {
> >     $values[] = " (NOW(), '{$v}') ";
> >   }
> >   if(count($values)) {
> >     $insert_sql = "INSERT INTO table_name (date, myValue) VALUES " .
> join("
> > VALUES ", $values);
> >     echo $insert_sql;
> >   } else {
> >     echo "Nothing to insert";
> >   }
> > }
> > ?>
> > <FORM METHOD=POST>
> >     <SELECT name='somename[]' size=10 multiple id='somename[]'>
> >         <OPTION value='one'>First Thingie</OPTION>
> >         <OPTION value='two'>Second Thingie</OPTION>
> >         <OPTION value='three'>Third Thingie</OPTION>
> >         <OPTION value='four'>Fourth Thingie</OPTION>
> >         <OPTION value='five'>Fifth Thingie</OPTION>
> >     </SELECT>
> >     <INPUT TYPE='SUBMIT'>
> > </FORM>
> >
> > Give the above script a shot and see if it does what you want it to do.
> >
> > Jim Lucas
> >
> > ----- Original Message -----
> > From: "Frank Keessen" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, June 03, 2003 11:55 AM
> > Subject: [PHP] Multi Selection
> >
> >
> > > Hi Guys,
> > >
> > > I'm trying to do the following:
> > >
> > > I've got a multiple selection box build out of a query of table
> > >
> > > <td><select name="VALUE[]" size="10" multiple id="VALUE[]">
> > >   <?
> > > $query2 = "SELECT SomethingID, Somewhere FROM Someplace WHERE
publiceer
> =
> > 'yes' ORDER BY somewhere";
> > > $result2 = mysql_query($query2) or die ("Error in query: $query2. " .
> > mysql_error());
> > >
> > > if (mysql_num_rows($result2) > 0)
> > >  {
> > >   while($row2 = mysql_fetch_object($result2))
> > >   {
> > > ?>
> > >
> > >     <OPTION VALUE="<? echo $row2->SomethingID ?>"><? echo
> $row2->Somewhere
> > ; ?>
> > > <?
> > >  }
> > > }
> > > ?>
> > > </option>
> > > </select>
> > >
> > > The outcome is stored in the VALUE[]..
> > >
> > > Now i want to have an INSERT query that insert each value seperatly..
> > >
> > > So if there are 3 selections it must be repeat the INSERT query three
> > times...
> > >
> > >
> > > Thanks for the help!
> > >
> > >
> > > Frank
> > >
> >
> >
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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

Reply via email to