logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-19-2012, 08:08 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default displaying dates

At last im trying to create my own programmes, but as expected im coming into a few sticking points that im struggling to overcome, please help.

this is my code to pull some posts from a database and it works fine, but it displays the date yyyy mm dd and I want to display it as dd month yy

$article = mysql_query("SELECT content, date FROM article ORDER BY date DESC");

while($row = mysql_fetch_array($article)){
echo "<p>" . $row['date'] . "<br/>" . $row['content'] . "</p>";
}

so I tried this:

$article = mysql_query("SELECT content, DATE_FORMAT(date, '%d %b %y') FROM article ORDER BY date DESC");

while($row = mysql_fetch_array($article)){
echo "<p>" . $row['date'] . "<br/>" . $row['content'] . "</p>";
}

and received the error undefined index.

what am i missing
tony09uk is offline   Reply With Quote
Old 04-20-2012, 01:14 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

i would just select date and then format. after. is it a timestamp?
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-20-2012, 09:04 AM   #3
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

I think so I have set it to NOW() when updates are made
tony09uk is offline   Reply With Quote
Old 04-21-2012, 12:49 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

try

$article = mysql_query("SELECT content, DATE_FORMAT(date, '%d %b %y') as date FROM article ORDER BY date DESC");
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 04-21-2012, 09:21 AM   #5
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default

Right then master guru ed, that work perfectly , many thanks! Now i have to ask why? Why was an Alias needed to make it work?
tony09uk is offline   Reply With Quote
Old 04-22-2012, 01:18 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

to be honest ive never thought about it, its a function and you have to name it to use it as a resource
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Reply


Thread Tools
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 On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:39 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com