MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 1st, 2000, 10:29 PM
Ole Ole is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Denmark
Posts: 53 Ole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 7 m 18 sec
Reputation Power: 14
Hi!
Some of you have probaly seen this before.....
I'm pretty new in this and have a problem about reformatting a DATE field from a mySQL db to DDMMYYYY.
After looking in the manual I tried this and it does not work:
<?PHP

MYSQL_CONNECT("127.0.0.1","root") OR DIE("No connection to database");
mysql_select_db("theater") OR DIE("Unable to find database");

$query = mysql_query("SELECT date_format(opening,'%d%m%Y'),headline,text,credits FROM opera ORDER BY opening");
ECHO "<TABLE WIDTH=100% BORDER=1 CELLSPACING=0 CELLPADDING=0>";

while($r = mysql_fetch_array($query)){

$headline = $r["headline"];
$opening = $r["opening"];
$text = $r["text"];
$credits = $r["credits"];

"<TR><TD>$headline</TD></TR><TR><TD VALIGN=top>Opening night: $opening</TD></TR><TR><TD VALIGN=top>$text</TD></TR><TR><TD VALIGN=top>$credits</TD></TR>
}
"</TABLE>";*/
}
?>
Everything else is showing as it should, but not at all the date! As I said, I'm pretty new in mySQL and PHP, but where did I go wrong???
Ole

Reply With Quote
  #2  
Old May 2nd, 2000, 08:28 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
Since you are using the mysql_fetch_array() and an associative array for the result, you can't just use "opening" as the index since you're returning the result of a function you've preformed on opening, rather than the value of opening itself. (To see what I mean, do your query at the command line and see how mysql labels the column.)

What you need to do is alias the result:

$query = mysql_query("SELECT date_format(opening,'%d%m%Y') AS f_open,headline,text,credits FROM opera ORDER BY opening");

Then use "f_open" as the index in the result array.

HTH

Reply With Quote
  #3  
Old May 2nd, 2000, 08:31 AM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
In your query, make date_format(opening,'%d%m%Y')into an aliased column by using ....date_format(opening, '%d%m%Y') as formatted_opening.....(or whatever alias you wish)

then use Opening night: $formatted_opening...

Reply With Quote
  #4  
Old May 3rd, 2000, 10:27 AM
Ole Ole is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Denmark
Posts: 53 Ole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 7 m 18 sec
Reputation Power: 14
It's working, thanks!!!
But I don't understand the %'s. As you told me and as far as I can see in the mySQL manual the correct way to make it is with %'s, but the result is that the date is displayed like %12.%4.%2000.
This way the date is displayed as it should:
$query = mysql_query("SELECT date_format(opening,'d.m.Y') AS f_open,headline,text,credits FROM opera ORDER BY f_open");
I'm working on Windows98 with 3.21.29a-gamma mySQL and PHP 3.0.14.

What about update? The data is also shown in a form, by which it should be possible to change the dates, texts and on, but I can't figure out how to change the date from DDMMYYYY (as it will be written in Denmark) to YYYYMMDD as mySQL wants it.
IF($update) {
MYSQL_CONNECT("127.0.0.1","root");
mysql_select_db("theater");
$query = MYSQL_QUERY("UPDATE opera SET headline = '$headline',opening = '$f_opening',tekst = '$tekst',credits = '$credits' WHERE headline = '$headline' ");
}

Ole, Denmark.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > MySQL/PHP date format

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap