Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php for each

Posted on 2013-02-05
5
Medium Priority
?
155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 59

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 143

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 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