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

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题