haliphax wrote:
> On Fri, Mar 6, 2009 at 3:00 PM, PJ <af.gour...@videotron.ca> 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);;
>> Â  Â }
> Phil, you don't want to use an INSERT if you're just updating an
> existing row. You can't do an INSERT and use the current row's values
> (book.id/book_id/whatever) in your insert, since there IS no current
> row. I'm assuming what you're trying to do is add a record to an
> associative table that links Categories to Books, but only if that
> Book title matches your $title string.
> Try this:
> foreach($categoriesIN as $category)
> $sql = "update book_categories set category = '$category' where
> book_id in (select id from book where title = '$titleIN')";
> If that's not what you're going for, and you just wanted to update
> something's category, try this:
> foreach($categoriesIN as $category)
> $sql = "update book_categories set category = '$category' where
> book_id = '$somevalue'";
> Perhaps it would help us help you if you would explain what it is
> you're trying to accomplish with this query?
Hmmm, maybe I'm chasing my own tail...
following the trail of execution is tough... :'(
I'm trying to enter a new book into the database and that means I have
to enter the info for the relational tables as well.
I think I stumbled here a bit as what I need is the id that is inserted
in the db before inserting this category stuff.
As I look at the code, it looks like i have to find the
"last-entered-id" for the book that is being entered.

unheralded genius: "A clean desk is the sign of a dull mind. "
Phil Jourdan --- p...@ptahhotep.com

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

Reply via email to