Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

php for each

I have select statement


select * from cdr where src ='103' and date BETWEEN $date1 and $date2  

Open in new window


I need to get for each day between $date1 and $date2 show the amounts

 $date1 is 03/02/2013  and $date2 = 05/02/2013   it would show results by each day

03/02/2013          04/02/2013          05/02/2013
id 10                      id 20                    id 30
client 20                Client 21              Client 60
0
beridius
Asked:
beridius
1 Solution
 
Julian HansenCommented:
It is not clear from your post what you are looking for.

What does your data look like and your table definition.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you want 1 column per date, right?
while "easy" in php, not simple in mysql at all.
please clarify
0
 
rinfoCommented:
Have you tried pivot sql query .Your answer lies in sql query.
http://stackoverflow.com/questions/4546433/pivot-sql-query-show-date-in-column
0
 
Ray PaseurCommented:
You might want to use the ISO-8601 DATETIME standard format, as described in this article.  The article is long, but it is the absolute minimum you must know if you want to handle date and time information correctly in your scripts and queries.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

After you have read that, you will understand why your query needs to look like this (note the quote marks!)...

SELECT col_name1, col_name2 FROM cdr WHERE src ='103' AND date BETWEEN '$date1' AND '$date2'

You probably do not want to use SELECT * if you can discern the column names that you want to select.  But that is a different issue and when you encounter an intractable performance problem you can post a new question on that topic.

Best to all, ~Ray
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now