Solved

php for each

Posted on 2013-02-05
5
154 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 58

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 110

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 110

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
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 …

636 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