What are the values for your checkbox?  I would consider making the 
value the index for the corresponding element.  So
<.input type=checkbox name='approved[]' value=0> <.input type='text' 
name='name[1]' value='John Smith'>
<.input type=checkbox name='approved[]' value=1> <.input type='text' 
name='name[1]' value='Russ the Great'>
<.input type=checkbox name='approved[]' value=2> <.input type='text' 
name='name[2]' value='Somebody Else'>
<.input type=checkbox name='approved[]' value=3> <.input type='text' 
name='name[3]' value='Somebody Altogether Different'>

Then in your PHP script, you could loop through the elements of 
$approved (as the only ones appearing would be the ones checked).
$insertsql = "";
for($i=0; $i<count($approved);$i++) {
        $insertsql  .= "insert into someTable (Name) VALUES('" . 
$name[$i] . "');";
}
$result = mysql_query($insertsql, $connection) or die(mysql_error());


Note, I also combined the queries into one larger query so that the 
database is only hit once instead of with each checked element.
Not positive you can do this in mysql, but I do it on Sybase quite 
frequently.

Hope this helps, feel free to contact me if you have other questions.
Rick Gardner

On Friday, September 21, 2001, at 09:59 AM, Russ Michell wrote:

> Hallo everyone
> I am, as one might say, 'near yet so far'....
>
> * I have a page of user subscription info generated on the fly
> * I want an administrator to check a box on each result set
> * The info from each checked result set should be inserted into another 
> table (A new row/tuple for
> each user)
>
> I am currently using each form element as an array to hold x number of 
> Names, Adresses etc. Where
> 'x' is the number of results generated, and consequently the number of 
> checkboxes generated.
>
> The processing script loops thru this and inserts only those results 
> that have been checked by the
> administrator in inserted in a new row.
>
> Using $HTTP_POST_VARS and dumping that to the page displays 
> (obviousely) 'array', 'array', etc.
> As each hidden form element is an array and also an $HTTP_POST_VARS 
> element)
> I need some way to extract the value of each array's keys so that they 
> can be used in an SQL INSERT.
>
> I'm using MySQL-3.22.32 and php4.0.3pl1
>
> Here is what I have as the processing script, but as you should be able 
> to see it is immedietley
> very limiting:
>
> while (list($key,$val) = each($Name)) {
>     $insertsql = "INSERT INTO $table_user (Name) VALUES ('$val')";
>     $result = mysql_query($insertsql, $connection) or 
> die(mysql_error());
>     }
>
> This simply INSERTS the values in the Name array, into a new row for 
> each name held in the array.
> Is it possible to somehow extend this loop or use a different kind of 
> loop to insert all the array
> values in this manner?
>
> Ideally it would work like this (This is JUST to illustrate the point, 
> I KNOW it won't work!!)
>
> while (list($key,$val) = each($Name,$Address,$Age,$Course)) {
>     $insertsql = "INSERT INTO $table_user (Name,Address,Age,Course) 
> VALUES
>     ('$valName','$valAddress','$valAge','$valCourse')";
>     $result = mysql_query($insertsql, $connection) or 
> die(mysql_error());
>     }
>
> Can anyone make any suggestions that would help me here?
> Many thanks in advance!
> Russ

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to