Re: insert array values

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

 



Bastien Koert wrote:
> On Fri, Mar 6, 2009 at 4:00 PM, PJ <af.gourmet@xxxxxxxxxxxx> wrote:
>
>   
>> I've been racking my little peanut-brain as well as big Google with
>> little hope...
>> I can retrieve the array from the multiple select dropdown box but I
>> can't quite manage to insert the data which is just id numbers for a table.
>> I've tried some while stuff but doesn't work. I know I don't have the
>> right syntax on anything at this point. Here's an effort that doesn' work.
>> Dont know if I should be using $categoriesIN[] type of stuff...
>> but my tries were from web illustrations...
>> the outcommented line returns the values of the array... but how to pass
>> them to the query?
>>
>> foreach ($categoriesIN as $category) {
>>    //"$category<br>";
>> $sql = "INSERT INTO book_categories ( book_id, category )
>>    VALUES( book.id WHERE title = $titleIN, $category )";
>>        $result = mysql_query($query, $db);;
>>    }
>> TIA
>>
>> --
>> unheralded genius: "A clean desk is the sign of a dull mind. "
>> -------------------------------------------------------------
>> Phil Jourdan --- pj@xxxxxxxxxxxxx
>>   http://www.ptahhotep.com
>>   http://www.chiccantine.com/andypantry.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>>     
> As its an array, you could join the data with an IMPLODE into a string, but
> does that meet your needs? The other option is to create a sub-table for
> this element and insert each item thru a loop individually.
>
>   
The returned array holds numbers like 1 or 2 or 3 or whatever up to60+
I need to enter the id of book.id into book_categories.book_id and the
values from the array into book_categories.categories_id.
book_categories is an intersecting table with foreign keys relating book
to categories.
The entries need to show the categories that are related to the book.
So, if the book.id = 1 and the categories id are 2, 4 and 5 I have to see
book_id  |   categories_id
--------------------------
   1     |       2        |
   1     |       4        |
   1     |       5        |
__________________________

At least, I think so... :-)
>From what I understood from all the posts and tutorials and manuals was
that my code should work unless I have made some syntax boo-boo.
I would think that this should be a series of inserts with only the
$category or $categoryIN changing...

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux