Solved

php for each

Posted on 2013-02-05
5
145 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 51

Expert Comment

by:Julian Hansen
Comment Utility
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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

743 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