0

I am trying to display my sql data in column wise. currently the output is

Customer Name       Amount          Date
XYZ                 1200            2015.01.01
XYZ                 600            2015.01.02

But i want to display like:

           2015.01.01       2015.01.2
XYZ        1200             600

My code is as below:

<!-- language: lang-html -->

    <table border="0" id="info">

    <?php
        $conn = mysql_connect('localhost','root','test');
        if(!$conn) die("Failed to connect to database!");
        $status = mysql_select_db('tulient', $conn);
        if(!$status) die("Failed to select database!");

        $sql = mysql_query("select * from add_deposite where CUSTOMER_NAME like '%$term%' and DATE between '$term1' and '$term2'");


        $rs = mysql_query("select * from add_deposite where CUSTOMER_NAME like '%$term%' and DATE between '$term1' and '$term2' ");
        $CUSTOMER_NAME = "";
            while($row = mysql_fetch_array($rs))
                {

                    echo '<tr>';
                    echo '<td><div align="left">'.$row['CUSTOMER_NAME'].'</div></td>';
                    echo '<td><div align="left">'.$row['AMOUNT'].'</div></td>';

                    echo '<td><div align="left">'.$row['DATE'].'</td>';
                    echo '</tr>';
                }

            ?> 
           </table>

Your valuable advice is necessary to complete my task. thanks in advance.

Ripon

dyatchenko
  • 2,283
  • 3
  • 22
  • 32
Ripon
  • 27
  • 6
  • Could you please try to re-format how you'd like it to look? It's not quite obvious as it is now. – johankj Feb 01 '15 at 12:22
  • This is called "pivoting," just so you know. – O. Jones Feb 01 '15 at 12:24
  • possible duplicate of [MySQL pivot table](http://stackoverflow.com/questions/7674786/mysql-pivot-table) – user2009750 Feb 01 '15 at 12:33
  • It's a multidimensional array, in which the dates become the keys, and the amounts the values – Strawberry Feb 01 '15 at 13:34
  • I guess to retrieve the data as you desire from sql itself, your query would look something like this: select customer, sum(amount), date from add_deposite group by customer, date – Tarske Feb 03 '15 at 06:37

0 Answers0