Solved

php for each

Posted on 2013-02-05
5
147 Views
Last Modified: 2013-03-05
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
Comment
Question by:beridius
5 Comments
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 38855147
It is not clear from your post what you are looking for.

What does your data look like and your table definition.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38855302
you want 1 column per date, right?
while "easy" in php, not simple in mysql at all.
please clarify
0
 
LVL 9

Expert Comment

by:rinfo
ID: 38858674
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 38866474
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38953293
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now