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

RE: [PHP] confused big time

2004-04-07 Thread Chris W. Parker
Andy B 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

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 colu

Re[2]: [PHP] confused big time

2004-04-07 Thread Richard Davey
Hello Mark, Wednesday, April 7, 2004, 6:35:31 PM, you wrote: MA> But what about MsSQL, Oracle and postgres to name a few. I have worked MA> on a few projects where you read from one db and load into another db. MA> Dates then become the spawn of satan. But the MySQL syntax for insert is not the

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[2]: [PHP] confused big time

2004-04-07 Thread Richard Davey
Hello Mark, Wednesday, April 7, 2004, 6:19:31 PM, you wrote: 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

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 tim

Re[2]: [PHP] confused big time

2004-04-07 Thread Richard Davey
Hello Mark, Wednesday, April 7, 2004, 5:16:04 PM, you wrote: MA> it builds the sql statement for you. It covers 99.9% of the inserts MA> your likely to need. I use an update and insert function like this all MA> the time. :-) That .1% of the time being when you need to insert a value as now()

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 => $valu

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

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']}', '{$array[

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

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

RE: [PHP] confused big time

2004-04-06 Thread Chris W. Parker
Andy B 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.

[PHP] [fixed!][PHP] confused big time

2004-04-06 Thread Andy B
ok query is fixed for the second one now... now to work on the if(!empty.. tests i have to check and make sure every one of those arrays isnt empty. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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: $s

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

[PHP] confused big time

2004-04-06 Thread Andy B
"MINE: $sql = " SELECT name , age , height , etc FROM user WHERE name = '$name' AND height = '5'";" um...im not doing selects im doing inserts with variable names... i understand the idea with

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: http://www.php.net/) To unsubscribe

[PHP] confused big time

2004-04-06 Thread Andy B
"two things i would recommend before disecting your code. 1. write readable queries. GOOD: $sql = " SELECT name , age , height , etc FROM user WHERE name = '$name' AND height = '5'"; 2. alway

RE: [PHP] confused big time

2004-04-06 Thread Chris W. Parker
Andy B 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 o

[PHP] confused big time

2004-04-06 Thread Andy B
hi... i have 2 mysql queries first one: //the extra { at the beginning and the extra , at the end of //each variable should be an '... "insert into $EventsTable values(NULL, '{$_SESSION[add][type]}', '{$_SESSION[add][start_date]}', '{$_SESSION[add][end_date]}', '{$_SESSION[add][name]}', '{$