This is a discussion on RE: [PHP] SQL statement within the PHP General forums, part of the PHP Programming Forums category; Dan J. Rychlik <mailto:drychlik@tcsconsult.com> on Tuesday, September 23, 2003 4:58 PM said: > I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Dan J. Rychlik <mailto:drychlik@tcsconsult.com>
on Tuesday, September 23, 2003 4:58 PM said: > I know its failing because php doesnt like the quotation before the > format parameters. Ive tried to fix this without any luck. Any > Ideas ? It's failing because the ' before the %d is closing the string. Here's how I work out SQL stuffs: $sql = "SELECT username\n" ." , password\n" ." , DATE_FORMAT(timestamp, '%d%m%y')\n" ."FROM custlogon"; $query = ($sql); Althought it looks like it takes a lot more time to write (which is true) it looks great when you are debugging. echo "<pre>$sql</pre>"; Alternatively you should be able to do this: $query = ("SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') FROM custlogon"); chris. |
|
|||
|
Ive used this
$query = ("SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') FROM custlogon"); But I recieve unknown index timestamp. *shrug* ----- Original Message ----- From: "Chris W. Parker" <cparker@swatgear.com> To: "Dan J. Rychlik" <drychlik@tcsconsult.com>; <php-general@lists.php.net> Sent: Tuesday, September 23, 2003 7:07 PM Subject: RE: [php] SQL statement > Dan J. Rychlik <mailto:drychlik@tcsconsult.com> > on Tuesday, September 23, 2003 4:58 PM said: > > > I know its failing because php doesnt like the quotation before the > > format parameters. Ive tried to fix this without any luck. Any > > Ideas ? > > It's failing because the ' before the %d is closing the string. > > Here's how I work out SQL stuffs: > > $sql = "SELECT username\n" > ." , password\n" > ." , DATE_FORMAT(timestamp, '%d%m%y')\n" > ."FROM custlogon"; > > $query = ($sql); > > > Althought it looks like it takes a lot more time to write (which is > true) it looks great when you are debugging. > > echo "<pre>$sql</pre>"; > > > Alternatively you should be able to do this: > > $query = ("SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') > FROM custlogon"); > > > > chris. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > |
|
|||
|
> Ive used this
> $query = ("SELECT username, password, DATE_FORMAT(timestamp, > '%d%m%y') FROM > custlogon"); > > But I recieve unknown index timestamp. *shrug* > > You are receiving the error on an array returned by fetch_array? If so, it is because the index is "DATE_FORMAT(timestamp, '%d%m%y')", not timestamp, which isn't so great. You can see this by doing a print_r on the array to see what is actually in it. Use aliasing in your query to give it a better index. "SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') as formatted_ts FROM custlogon" or something like that. |
|
|||
|
Jennifer, you're right, I am using fetch_array... I tried to use your
suggestion, and it failing as well, It wont even execute.... Do you have a better method of looping through all these records?? ----- Original Message ----- From: "Jennifer Goodie" <goodie@apollointeractive.com> To: "Dan J. Rychlik" <drychlik@tcsconsult.com>; "Chris W. Parker" <cparker@swatgear.com>; <php-general@lists.php.net> Sent: Tuesday, September 23, 2003 7:15 PM Subject: RE: [php] SQL statement > > Ive used this > > $query = ("SELECT username, password, DATE_FORMAT(timestamp, > > '%d%m%y') FROM > > custlogon"); > > > > But I recieve unknown index timestamp. *shrug* > > > > > You are receiving the error on an array returned by fetch_array? If so, it > is because the index is "DATE_FORMAT(timestamp, '%d%m%y')", not timestamp, > which isn't so great. You can see this by doing a print_r on the array to > see what is actually in it. Use aliasing in your query to give it a better > index. > "SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') as formatted_ts > FROM custlogon" or something like that. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > |
|
|||
|
On Tue, 23 Sep 2003 19:10:29 -0500
"Dan J. Rychlik" <drychlik@tcsconsult.com> wrote: > Ive used this > $query = ("SELECT username, password, DATE_FORMAT(timestamp, > '%d%m%y') FROM custlogon"); > > But I recieve unknown index timestamp. *shrug* > Is "timestamp" an actual columnname in your table? -- Raquel ================================================== ========== It is easy to take liberty for granted when you have never had it taken from you. --M. Grundler -- Raquel ================================================== ========== It is easy to take liberty for granted when you have never had it taken from you. --M. Grundler |
|
|||
|
This didnt work as well.
SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') as formatted_ts FROM custlogon; It caused my script to die and not execute at all.... ----- Original Message ----- From: "Jennifer Goodie" <goodie@apollointeractive.com> To: "Dan J. Rychlik" <drychlik@tcsconsult.com>; "Chris W. Parker" <cparker@swatgear.com>; <php-general@lists.php.net> Sent: Tuesday, September 23, 2003 7:15 PM Subject: RE: [php] SQL statement > > Ive used this > > $query = ("SELECT username, password, DATE_FORMAT(timestamp, > > '%d%m%y') FROM > > custlogon"); > > > > But I recieve unknown index timestamp. *shrug* > > > > > You are receiving the error on an array returned by fetch_array? If so, it > is because the index is "DATE_FORMAT(timestamp, '%d%m%y')", not timestamp, > which isn't so great. You can see this by doing a print_r on the array to > see what is actually in it. Use aliasing in your query to give it a better > index. > "SELECT username, password, DATE_FORMAT(timestamp, '%d%m%y') as formatted_ts > FROM custlogon" or something like that. > |