[thelist] MySQL/PHP Associative Array Insert

CDitty mail at redhotsweeps.com
Sat Feb 1 10:46:00 CST 2003


Looks like you understood it correctly.  Your example is exactly what I
needed.  I didn't realize that with associative arrays
I would have to '" . $item['itemID'] . "'.  This will get me moving again.

Thank you
Chris

At 10:41 AM 2/1/2003, you wrote:
> > Can someone give me an example of how to do an insert to the
> > database using these arrays?  My array is this...$item['itemID']
>
>Maybe I'm not understanding the question clearly, but if I do you should
>be able to use the array values just as you would any variable.
>
>Here's a function I use to update announcement items in a calendar app
>that takes an array as you described, $data is the array (like your
>$item) and $update is a switch that tells the function whether to update
>or insert, defaulting to insert:
>
>// update announcement item
>function update_announcement($data, $update=0) {
>         $connect = dbconnect();
>         $query = "UPDATE cal_announcements
>                     SET
>                         user_id='".$data['user_id']."',
>                         s_date='".$data['s_date']."',
>                         e_date='".$data['e_date']."',
>                         title='".$data['title']."',
>                         content='".$data['content']."'
>                     WHERE annc_id='".$data['annc_id']."'";
>         if (empty($update)) {
>                 $query = "INSERT INTO cal_announcements
>                                 (user_id,s_date,e_date,title,content)
>                             VALUES
>                                 ('".$data['user_id']."',
>                                 '".$data['$s_date']."',
>                                 '".$data['e_date']."',
>                                 '".$data['title']."',
>                                 '".$data['content']."')";
>         }
>         $result = mysql_query($query) or die (mysql_error());
>}
>
>HTH.
>
>BH
>
>--
>* * Please support the community that supports you.  * *
>http://evolt.org/help_support_evolt/
>
>For unsubscribe and other options, including the Tip Harvester
>and archives of thelist go to: http://lists.evolt.org
>Workers of the Web, evolt !




More information about the thelist mailing list