Page 1 of 1

sending array to sql query

Posted: Fri Mar 25, 2005 8:54 am
by dprasad
I want to append multiple selections from a multi select to a database field. The problem is that only the first selection gets appended to the db. The problem is that the array($findkwresult[$no];) only gets set to the first value, any subsquent iterations dont have any values loaded into them:

Code: Select all

while (OCIFetchInto ($s1, $row, OCI_ASSOC)) {
                  
                           $findkwresult = array();
                $findkwresult[] = $row['KEYWORDID'];
}
$selecttype = $_POST['selecttype'];

if(isset($_POST['keywordparam'])){
    for($no=0;$no<count($_POST['keywordparam']);$no++){
        $keywordelement = $_POST['keywordparam'][$no];
echo 'findkwresult' . $findkwresult[$no];
               echo 'keywordelement' . $keywordelement;
               //$updateq = "update k3gisdcp.keywords set keyword = keyword ||  '" . $keywordelement . "' where keyword_id = '" . $findkwresult ."'" ;
               $updateq = "update k3gisdcp.keywords set keyword = keyword ||  'keyword: " . $keywordelement . "' where keyword_id = '{$findkwresult[$no]}'";
               $s2 = OCIParse($c1, $updateq) or die("update error : $updateq");
               OCIExecute($s2);
               $committed2 = ocicommit($c1);

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Mar 25, 2005 9:08 am
by feyd
what type is this database field?

Posted: Fri Mar 25, 2005 9:16 am
by dprasad
its an oracle varchar2

Posted: Fri Mar 25, 2005 9:32 am
by feyd
not fully up on Oracle syntax versus other sql, but...

Code: Select all

$updateq = 'update k3gisdcp.keywords set keyword = CONCAT(keyword,\' || ' . $keywordelement . '\') where keyword_id = \'' . $findkwresult&#1111;$no] . '\'';
Although I'd implode() the array first, so it only takes 1 query to update the field.