Re: two inserts at once?

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

 



Well what do ya know, this works! Thanks for the pointer.

if ($tableid=="newfaq") {
      echo "adding FAQ<BR>";
      $newfaq_query =  "INSERT INTO `faq` (`faqid`, `question`, `answer`)
VALUES ('', '$question', '$answer')";
      $newfaqResult = mysql_query($newfaq_query);
      $newfaq_query2 = "INSERT into `faqRelatedToProduct` (`id`,
`fgNumber`, `faqid`) VALUES ('', '$fgNumber', last_insert_id() )";
      $newfaqResult2 = mysql_query($newfaq_query2);
      echo $newfaq_query."<BR>".$newfaq_query2;
}

Michael



                                                                                                                                         
                      Jason Wong                                                                                                         
                      <php-db@gremlins.        To:       php-db@lists.php.net                                                            
                      biz>                     cc:                                                                                       
                                               Subject:  Re:  two inserts at once?                                               
                      01/09/03 01:08 PM                                                                                                  
                      Please respond to                                                                                                  
                      php-db                                                                                                             
                                                                                                                                         
                                                                                                                                         




On Friday 10 January 2003 01:04, Michael Knauf/Niles wrote:
> This Code Snippet works:
>
> $newfaq_query =  "INSERT INTO `faq` (`faqid`, `question`, `answer`)
VALUES
> ('', '$question', '$answer')";
> $newfeaturesResult = mysql_query($newfeatures_query);
>
> But I'd like to combine that query with this one:
>
> INSERT INTO `faqRelatedToProduct` (`id`, `fgNumber`, `faqId`) VALUES ('',
> '$fgNumber', '$faqid');
>
> So that both are executed at the same time.

The current php-mysql interface only allows single queries at a time.

> The variables $question, $answer, $fgNumber come from a form, the faqid
is
> a auto increment field, as is id... but it seems I need to know the value
> of faqid to relate it correctly to the fgNumber...

The retrieve faqid use mysql_insert_id().

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


/*
The more you sweat in peace, the less you bleed in war.
*/


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

Niles Audio Corporation
This mail is confidential







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