1

What I want is show the total clicks per Category id of the items only for 20 items order by the highest total clicks per day.

Now I am using hard code and the result have to looks like this

i am using hard code to t

So, if the item id and total clicks already fill up the

20columns (for item id and total clicks) + 2 for the tittle so means

22columns

It has to move to next row.

Because I am referring to my db, so I am using loop to create the table, and when I doing that way, I am getting this result....

enter image description here

The result will keep showing until the end in the left side. Thats very hard to read for report purposes. I wanted the result looks like the first figure that I've uploaded.

Here is what I am doing now:

  include "Con.php";
        //get the value from Get Method 
        $CatidValue = $_GET['CatIds'];
        //(The date format would looks like yyyy-mm-dd)
        $DateFrom = $_GET['DateFrom'];  
        $DateTo = $_GET['DateTo'];
        //select the CatID
        $SqlGet= "Select CatId from try where CatId = $CatidValue";
        $_SqlGet = mysqli_query($connection,$SqlGet);
        $TakeResultGet = mysqli_fetch_array($_SqlGet);
        $CatIdTittle = $TakeResultGet ['CatId'];

        echo"
            For Category Id : $CatIdTittle
            <br>
                    
        ";
        
        //For Loop purpose and break the value
        $explodeValueFrom = explode("-",$DateFrom);
        $explodeValueTo = explode("-",$DateTo);
        $DateValueFrom = $explodeValueFrom[0].$explodeValueFrom[1].$explodeValueFrom[2];
        $DateValueTo = $explodeValueTo[0].$explodeValueTo[1].$explodeValueTo[2];    
        
        //Loop through the date
        for($Loop=$DateValueFrom; $Loop <= $DateValueTo; $Loop++){
            $YearLoop= substr($Loop, 0,4);
            $MonthLoop =substr($Loop, 4,2);
            $DayLoop = substr($Loop, 6,2);

            $DateTittleValue = $YearLoop."-".$MonthLoop."-".$DayLoop;
            $trValue = "<th class='tg-amwm' colspan='2'>$DateTittleValue</th>";

                
                echo"
                <table class='tg'>
                    <tr>
                        $trValue
                    </tr>
                ";
                echo"
                <table class='tg'>
                    <tr>
                        <td class='tg-yw4l'>Items Id</td>
                        <td class='tg-yw4l'>Total Clicks</td>
                    </tr>
                ";
            
        
            
            //to get the item id and total clicks
            $SqlSelect = "select `Item Id`,`Total Clicks`,Day from try where CatId = $CatidValue and Day = '$DateTittleValue' ORDER BY `try`.`Total Clicks`  DESC limit 20";
            $_SqlSelect = mysqli_query($connection,$SqlSelect);
            foreach ($_SqlSelect as $ResultSelect) {
                $Day = $ResultSelect['Day'];
                $ItemId = $ResultSelect['Item Id'];
                $TotalClicks = $ResultSelect['Total Clicks'];

                echo"       
                    <tr>
                        <td class='tg-yw4l'>$ItemId</td>
                        <td class='tg-yw4l'>$TotalClicks</td>
                    </tr>               
                ";
            }
        }           
    ?>
2
  • You can achieve that with the help of CSS and some float magic. Just place each of those tables inside a div, and make them float to the left. Commented Sep 29, 2016 at 3:41
  • @LeonelAtencio "Float Magic"? Commented Sep 29, 2016 at 3:45

3 Answers 3

3

you need to add td dynamically within a table for each day report ( data should be grouped by date).

Sign up to request clarification or add additional context in comments.

1 Comment

what you are saying was right, but the answer from @Leonel Atencio is suitable for my case. Thank you!
1

You just need to float each table with the float:left css property and some percentage based on the number of tables you want on the same row. In this case, 33% will do. Take a look at this codepen: http://codepen.io/anon/pen/EgXqPk

The magic happens on:

.tg {
  width: 33%;
  float:left;
}

2 Comments

You are the best ! this is the answer
Glad i helped. If this answer it for you, please accept it!.
1
you can try i hope this perfect for you to draw a table using PHP Loop.
<?php  
echo "<table border =\"1\" style='border-collapse: collapse'>"; 
for ($row=1; $row <= 10; $row++) { 
echo "<tr> \n";
for ($col=1; $col <= 10; $col++) { 
$p = $col * $row;
echo "<td>$p</td> \n";
 }
echo "</tr>";
}
echo "</table>";
?>  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.