[PHP] Question About Date Function in PHP/MySQL

2004-02-08 Thread Freedomware
I'm using PHP to display a MySQL table. I've got everything working fine 
except the date function.

I designated the first two fields VARCHAR. Those columns display just 
fine when I preview my web page, as do all the other columns except the 
third. I designated that one DATE. (The field name is Birthday.)

When I view my data in phpMyAdmin, all I see in that column is NULL. 
When I preview it in a webpage, nothing displays at all. If I change it 
to NOT NULL, I see -00-00 in every cell.

Here's a row of text from the CSV file I imported into my MySQL table:

Alberta,Edmonton,1905-09-01,11,NWT,AB,CAN

As you can see, the date is listed as 1905-09-01.

I've altered my MySQL table every way I can think of, and nothing works. 
The MySQL Manual doesn't shed any light on it. So I'm wondering if 
there's something wrong with my PHP code.

Below's the source code from my web page. Do you see anything that would 
cause the third column - echo $myrow[Birthday]; - to malfunction, 
while everything else works fine?

Thanks.

?php
$db = mysql_connect(localhost, USERNAME, PASSWORD);
mysql_select_db(test,$db);
$result = mysql_query(SELECT * FROM states,$db);
echo table;
echotrtdbName/btdbCapital/btdbBirthday/btdbRank/bbOrigin/bbCode/btdbNation/b/tr;
while($myrow = mysql_fetch_array($result))
{
echo trtd;
echo $myrow[Name];
echo /tdtd;
echo $myrow[Capital];
echo /tdtd;
echo $myrow[Birthday];
echo /tdtd;
echo $myrow[Rank];
echo /tdtd;
echo $myrow[Origin];
echo /tdtd;
echo $myrow[Code];
echo /tdtd;
echo $myrow[Bigcode];
echo /td/tr;
}
echo /table;
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question About Date Function in PHP/MySQL

2004-02-08 Thread John W. Holmes
Freedomware wrote:

When I view my data in phpMyAdmin, all I see in that column is NULL. 
When I preview it in a webpage, nothing displays at all. If I change it 
to NOT NULL, I see -00-00 in every cell.

Here's a row of text from the CSV file I imported into my MySQL table:

Alberta,Edmonton,1905-09-01,11,NWT,AB,CAN

As you can see, the date is listed as 1905-09-01.
Well, that's the right format for a MySQL date; -MM-DD, so I don't 
know why it wouldn't load from your CSV file. Can you show the command 
that you use to import the file? If the fields are NULL (or -00-00) 
in the database, then MySQL is not accepting your data (for the date 
field at least).

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question About Date Function in PHP/MySQL

2004-02-08 Thread Freedomware
John W. Holmes wrote:

Freedomware wrote:

When I view my data in phpMyAdmin, all I see in that column is NULL. 
When I preview it in a webpage, nothing displays at all. If I change 
it to NOT NULL, I see -00-00 in every cell.

Here's a row of text from the CSV file I imported into my MySQL table:

Alberta,Edmonton,1905-09-01,11,NWT,AB,CAN

As you can see, the date is listed as 1905-09-01.


Well, that's the right format for a MySQL date; -MM-DD, so I don't 
know why it wouldn't load from your CSV file. Can you show the command 
that you use to import the file? If the fields are NULL (or -00-00) 
in the database, then MySQL is not accepting your data (for the date 
field at least).
Wow, I think you solved it! I went to retrieve the link to the screen 
shots I put online when I was first trying to figure this stuff out - at 
http://geowebworks.geobop.org/test/php/

Towards the bottom of the page (#6) is a screen shot of something I was 
oblivious to this time around - Date and Time Formats. (I'm using a 
trial version of EMS MySQL Manager.)

I'll bet that's my problem, though I'm still a bit confused.

EMS lists the following:

Short Date: M/d/
Long Date: ,  dd, 
Day followed by month, followed by another day, then year???

I thought it was supposed to be year first, followed by month and day, 
as in the example from CSV table - 1905-09-01.

Should I change Long Date so that it reads -MM-DD, or something like 
that? Or maybe I can figure out how to do it in phpMyAdmin. I downloaded 
EMS phpMySQL because I couldn't create error-free tables with 
phpMyAdmin, but maybe I can use it to tweak my tables.

Thanks for the tip!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question About Date Function in PHP/MySQL

2004-02-08 Thread John W. Holmes
Freedomware wrote:

EMS lists the following:

Short Date: M/d/
Long Date: ,  dd, 
Day followed by month, followed by another day, then year???
That format means something like Friday, May 5, 2004

I thought it was supposed to be year first, followed by month and day, 
as in the example from CSV table - 1905-09-01.

Should I change Long Date so that it reads -MM-DD, or something like 
that? 
Yeah, I'd try switching possibly both the long and short dates to 
-MM-DD and see if it's imported correctly.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Question About Date Function in PHP/MySQL

2004-02-08 Thread Freedomware
John W. Holmes wrote:
Freedomware wrote:

EMS lists the following:

Short Date: M/d/
Long Date: ,  dd, 
Day followed by month, followed by another day, then year???


That format means something like Friday, May 5, 2004

I thought it was supposed to be year first, followed by month and day, 
as in the example from CSV table - 1905-09-01.

Should I change Long Date so that it reads -MM-DD, or something 
like that? 


Yeah, I'd try switching possibly both the long and short dates to 
-MM-DD and see if it's imported correctly.

OK, I'll add that to my experiments to do list. In the meantime, I 
imported all the dates as VARCHAR, then went into phpMyAdmin and changed 
it to DATE. It seems to work!

Thanks again for the tips.

Oh, one other thing... Do you know if dates can be sorted in various 
ways, either by absolute date or by month alone, date alone, etc.? I'm 
going to be making sortable columns (JavaScript or PHP), and I'm not yet 
sure what all you can do with dates.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php