Re: INSERT Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John,
Thanks. Yes that is a big help. The radio button is actually not used for that purpose (sorry that was a bit confusing of me to put in without an explanation). For each person selected, the radio button Y/N relates to whether they are an author of the report or just a contributer. I assume, the radio button can be handled the same way and I can just extrapolate your example to figure that out - I think ;)


- Charles


On Saturday, March 29, 2003, at 05:46 PM, John W. Holmes wrote:


Since I don't totally understand (newbie) I will show you an example
of
the form.

<form>
<select name="person1">
<option value="1">Joe Smith</option>
etc.
</select>
<input type="radio" name="person1yn" value="Yes"> Y <input
type="radio"
name="person1yn" value="No"> N

So if the 'Y' radio button is chosen, you'll want to take that 'person' and input them into the table?

First, the easy way would be to lose the radio button and just put a
"Choose Person" option in the <select> dropdown. Then, only process the
names if it's not "Choose Person"...

Even if you can't lose the radio buttons, you'll need to make everything
arrays so they are easier to process.


<form>
<select name="person[]">
<option value="0">Choose Person</option>
<option value="1">Joe Smith</option>
...
</select>

Then, to process that (assuming POST) you'd use:

Foreach($_POST['person'] as $person_id)
{
	if($person_id > 0)
	{ $insert[] = "('$person_id')"; }
}
$sql = "INSERT INTO table (person_id) VALUES " . implode(',',$insert);

Then run $sql... The second part loops through each "person" select and
makes sure the value isn't zero before it creates the ('value') part of
the SQL. The implode() at the end of the $sql line takes each ('value')
part and joins them into a string separated by a comma.

Does that help at all?

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux