RE: [PHP] SQL statement

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


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-24-2003
Chris W. Parker
 
Posts: n/a
Default 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.
Reply With Quote
  #2 (permalink)  
Old 09-24-2003
Dan J. Rychlik
 
Posts: n/a
Default 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*


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

Reply With Quote
  #3 (permalink)  
Old 09-24-2003
Jennifer Goodie
 
Posts: n/a
Default 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.
Reply With Quote
  #4 (permalink)  
Old 09-24-2003
Dan J. Rychlik
 
Posts: n/a
Default Re: [PHP] SQL statement

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
>

Reply With Quote
  #5 (permalink)  
Old 09-24-2003
Raquel Rice
 
Posts: n/a
Default Re: [PHP] SQL statement

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
Reply With Quote
  #6 (permalink)  
Old 09-24-2003
Dan J. Rychlik
 
Posts: n/a
Default Re: [PHP] SQL statement

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:54 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0