Re: INSERT Question

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

 



Got it working - well actually not this exact form (I am will get to that) but another which uses checkboxes (which is basically the same idea).

Here is what I did and this is a bit different because I am using HTML_QuickForm which does not allow me to use a name like name="fieldname[]"

so my form ended up looking like this:

<input name="ib_article[30]" type="checkbox" value="1" />Test A
<input name="ib_article[20]" type="checkbox" value="1" />Test B
<input name="ib_article[31]" type="checkbox" value="1" />Test C

(this part of the form above was built with a loop from an articles table.

so... then this form gets submitted and I did this:

$article_arr = $ib_form->getSubmitValue("ib_article"); // this gets the array passed from QuickForm
$article_keys = array_keys($article_arr); // this sets a variable to an array of the keys


then I built the INSERT like so:
foreach($article_keys as $articleid)
{
$insert[] = "('$v_ib_id','$articleid')";
}
$article_sql = "INSERT INTO tbl_ib_articles (issue_brief,article) VALUES " . implode(',',$insert);


Thanks to you both for all the help.

- Charles


On Saturday, March 29, 2003, at 09:21 PM, John W. Holmes wrote:


The only addition I have is to adapt the code to create a single INSERT
query in the format I gave earlier. It will run quicker overall.

---John W. Holmes...

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

-----Original Message-----
From: Charles Kline [mailto:ckline@rightcode.net]
Sent: Saturday, March 29, 2003 9:11 PM
To: Peter Lovatt
Cc: php-db@lists.php.net
Subject: Re:  INSERT Question

Big help! Thanks much.

Now... to figure out how to create that kind of form in HTML_QuickForm
(hehehe). If I can't then I just make it by hand, but now I know the
method! Phew... always more to learn.

- Charles


On Saturday, March 29, 2003, at 08:51 PM, Peter Lovatt wrote:


Hi

you need to create 5 selects, all named investigator[] with index
1-5
(or
0-4), with the option set to empty for no selection.

this will return an array
investigator[1] => '1064618047'
investigator_yesno[1] => 'Y'

investigator[2] => '1649815377'
investigator_yesno[2] => 'N'

for example


<form> <table> <tr> <td> <select name="investigator[1]"> <option value="">Choose person</option> <option value="1064618047">Paul A</option> <option value="1655387822">Katrina A</option> <option value="1649815377">David A</option> </select> is a primary investigator? <input name="investigator_yesno[1]" value="Y" type="radio" checked="checked" />Yes <input name="investigator_yesno[1]" value="N" type="radio" />No </td> </tr> <tr> <td> <select name="investigator[2]"> <option value="">Choose person</option> <option value="1064618047">Paul A</option> <option value="1655387822">Katrina A</option> <option value="1649815377">David A</option> </select> is a primary investigator? <input name="investigator_yesno[2]" value="Y" type="radio" checked="checked" />Yes <input name="investigator_yesno[2]" value="N" type="radio" />No </td> </tr> ...more here .... </table> </form>



on the script receiving the data you  then need a for loop to insert
the
records, one for each person


for ($i = 1; $i <= 4; $i++) { //only do it if there is a value for $investigator[$i], ie there is
a
selection
if($investigator[$i]) {
    $query = 'INSERT INTO tbl_report_people
                (record_id
                , person_id
                , investigator_yesno
                )
                VALUES
                ("'.$record_id[$i].'"
                , "'.$investigator[$i].'"
                , "'.$investigator_yesno[$i].'"
                )
                                ';
    $mysql_result = mysql_query($query, $mysql_link);

}//end if

}//end for



hope this helps

Peter







--
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




--
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