Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Pad empty dates? ( MYSQL )
Old 05-25-2011, 03:26 AM Pad empty dates? ( MYSQL )
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Hi guys,

Ive got the following:

mysql> SELECT id, created, status FROM incidents WHERE created > DATE_SUB(NOW(), INTERVAL 30 day);
+------+---------------------+--------+
| id | created | status |
+------+---------------------+--------+
| 1058 | 2011-04-27 11:22:19 | 0 |
| 1059 | 2011-05-10 10:16:06 | 0 |
| 1060 | 2011-05-20 03:33:03 | 0 |
| 1061 | 2011-05-24 14:28:55 | 1 |
+------+---------------------+--------+

Great, That gives me rows from the last month/30 odd days...

Anyway..
How can I pad dates that dont have rows? ( If this can be done in php .. how? )

Ie so it responds with:
mysql> SELECT id, created, status FROM incidents WHERE created > DATE_SUB(NOW(), INTERVAL 30 day);
+------+---------------------+--------+
| id | created | status |
+------+---------------------+--------+
| 1058 | 2011-04-27 11:22:19 | 0 |
| 1059 | 2011-05-10 10:16:06 | 0 |
| 1060 | 2011-05-11 03:33:03 | 0 |
| 1060 | 2011-05-12 03:33:03 | 0 |
| 1060 | 2011-05-13 03:33:03 | 0 |
| 1060 | 2011-05-1403:33:03 | 0 |
| 1060 | 2011-05-15 03:33:03 | 0 |
etc ( until a real row comes up )
| 1061 | 2011-05-24 14:28:55 | 1 |
+------+---------------------+--------+
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
 
Register now for full access!
Old 05-27-2011, 08:26 AM Re: Pad empty dates? ( MYSQL )
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
For the SQL server to handle that you would need write a stored procedure.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Pad empty dates? ( MYSQL )
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10250 seconds with 12 queries