RE: [PHP] confused big time

2004-04-07 Thread Robert Cummings
On Tue, 2004-04-06 at 20:09, Chris W. Parker wrote: Chris W. Parker on Tuesday, April 06, 2004 5:01 PM said: let me expand both of my points in an attempt to be more verbose. 1. write readable queries. 2. always put single quotes around array keys. $array['key'] here is how i

Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
I always found this way of inserting data into a database messy. Here is a handy function to do array inserts and it builds the sql for you. function arrayINSERT($a,$tablename) { $sql = INSERT INTO $tablename (; foreach($a as $key = $value)

Re: [PHP] confused big time

2004-04-07 Thread John W. Holmes
From: Mark Ackroyd [EMAIL PROTECTED] I always found this way of inserting data into a database messy. Here is a handy function to do array inserts and it builds the sql for you. function arrayINSERT($a,$tablename) { $sql = INSERT INTO $tablename (; foreach($a as $key = $value) { $sql

Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
RD That .1% of the time being when you need to insert a value as now() ? RD (which will break the string check as it'll wrap it with '' which will RD cause MySQL to insert -00-00 00:00:00) or if it's an enum field RD with a numeric allowed value? :) Not really, since you usally format a

Re: [PHP] confused big time

2004-04-07 Thread Mark Ackroyd
RD But now() IS a DB friendly format for MySQL and is the recommended RD way of inserting the current time into a datetime or timestamp RD field. But what about MsSQL, Oracle and postgres to name a few. I have worked on a few projects where you read from one db and load into another db. Dates

Re: [PHP] confused big time

2004-04-07 Thread Red Wingate
You could even do: $sql .= ( '.implode( ',' , $a ).' ); This way everything is quoted though ( but this doesn't matter using MySQL anyway ). If you want to escape the values of $a you could use array_map to do this also without having to loop :-) -- red [...] To get your list of columns,

RE: [PHP] confused big time

2004-04-07 Thread Chris W. Parker
Andy B mailto:[EMAIL PROTECTED] on Tuesday, April 06, 2004 7:56 PM said: $query=insert into table values( '{$array['index1']['index2']}', '{$array[index2']['index3']}', //so on down the list ); if i understand the readable way right... no, not quite. here is how you should do it

Re: [PHP] confused big time

2004-04-07 Thread Andy B
- Original Message - From: Chris W. Parker [EMAIL PROTECTED] To: Andy B [EMAIL PROTECTED] Sent: Wednesday, April 07, 2004 6:30 PM Subject: RE: [PHP] confused big time Andy B mailto:[EMAIL PROTECTED] on Wednesday, April 07, 2004 2:09 PM said: yes you can absolutely do it that way

RE: [PHP] confused big time

2004-04-06 Thread Chris W. Parker
Andy B mailto:[EMAIL PROTECTED] on Tuesday, April 06, 2004 4:51 PM said: they both use the same identical format to insert the arrays. there is an interesting problem though: the first one complains about use of undefined constant add - assumed 'add' in the second query...the first one

RE: [PHP] confused big time

2004-04-06 Thread Chris W. Parker
Chris W. Parker on Tuesday, April 06, 2004 5:01 PM said: let me expand both of my points in an attempt to be more verbose. 1. write readable queries. 2. always put single quotes around array keys. $array['key'] here is how i would write your query: ?php $sql = insert into

Re: [PHP] confused big time

2004-04-06 Thread Richard Davey
Hello Andy, Wednesday, April 7, 2004, 1:06:52 AM, you wrote: AB 1. how were those queries unreadable?? and You're kidding, right? AB 2. whenever i put '' around the array keys in multi dimensional arrays in a AB query i get a parse error of trying to use undefined keys or it doesnt AB expand

Re: [PHP] confused big time

2004-04-06 Thread Richard Davey
Hello Andy, Wednesday, April 7, 2004, 1:18:06 AM, you wrote: AB um...im not doing selects im doing inserts with variable names... i AB understand the idea with select but thats not the dealits an insert... He was showing you a neatly formatted query, the example applies to inserts too:

RE: [PHP] confused big time

2004-04-06 Thread Chris W. Parker
Andy B mailto:[EMAIL PROTECTED] on Tuesday, April 06, 2004 5:18 PM said: um...im not doing selects im doing inserts with variable names... i understand the idea with select but thats not the dealits an insert... i was hoping that wouldn't cause any confusion, but i guess it did. the

RE: [PHP] confused big time

2004-04-06 Thread Martin Towell
um...im not doing selects im doing inserts with variable names... i understand the idea with select but thats not the dealits an insert... i was hoping that wouldn't cause any confusion, but i guess it did. the thing to remember is that a query is a query. you know, parts is

Re: [PHP] confused big time

2004-04-06 Thread Andy B
He was showing you a neatly formatted query, the example applies to inserts too: $sql = INSERT INTO tablename ( field1, field2, field3 ) VALUES ( '$blah', $here',

Re: [PHP] confused big time

2004-04-06 Thread Andy B
AB 1. how were those queries unreadable?? and You're kidding, right? sorry...my bad... never had any writing readable code help anywhere...guess if i do it like c/c++ then it would work better AB 2. whenever i put '' around the array keys in multi dimensional arrays in a AB query i get a

Re: [PHP] confused big time

2004-04-06 Thread Andy B
i was hoping that wouldn't cause any confusion, but i guess it did. the thing to remember is that a query is a query. you know, parts is parts. oops stress and the fact that im sort of new at this stuff mixed me up... $query=insert into table values( '{$array['index1']['index2']}',