dougui1977 2016-09-29 03:21
浏览 79
已采纳

在Php中创建带循环的表

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>               
                ";
            }
        }           
    ?>
  • 写回答

3条回答 默认 最新

  • doulun1915 2016-09-29 03:57
    关注

    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条)

报告相同问题?

悬赏问题

  • ¥50 有偿求qftp工具。能连接,下载文件,发送代码,windows环境,最好qt6 要qt creator写的
  • ¥70 刚刚看到一个人的网站居然是通过cname访问的
  • ¥15 Attributeerror:super object has no attribute '__sklearn_tags__'_'
  • ¥15 逆置单链表输出不完整
  • ¥15 宇视vms-B200-A16@R启动不了,如下图所示,在软件工具搜不到,如何解决?(操作系统-linux)
  • ¥500 寻找一名电子工程师完成pcb主板设计(拒绝AI生成式答案)
  • ¥15 关于#mysql#的问题:UNION ALL(相关搜索:sql语句)
  • ¥15 matlab二位可视化能否针对不同数值范围分开分级?
  • ¥15 已经创建了模拟器但是不能用来运行app 怎么办😭自己搞两天了
  • ¥15 关于#极限编程#的问题,请各位专家解答!