RE: Multiple inserts revisited

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

 



> -----Original Message-----
> From: Becoming Digital [mailto:subs@becomingdigital.com]
> Sent: 28 May 2003 23:38
> 
> My other option, as I saw it, was to loop through the items, 
> appending value
> data to the query text with each iteration.  If that seems 
> cryptic, here's a
> basic idea of what I mean.
> 
> <?
> $query = "INSERT INTO specials VALUES ("
> foreach ( $specials as $item ) {
>     $query = substr_replace( $query, $item.", ", strlen( $query ) );
> }
> $query = substr_replace( $query, ")", strlen( $query )-2 );
> ?>
> 
> If $specials was an array with the values spec1, spec2, and 
> spec3, the final
> value of $query would be:
>     INSERT INTO specials VALUES (spec1, spec2, spec3)

I'm actually slightly dubious that this query *does* do what you want, but if you've double-checked it and it does, then this is a somewhat more compact way of producing it:

  $query = "INSERT INTO specials VALUES (" . implode(',', $specials) . ')'

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211 

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