douxuzui4590 2017-08-18 09:06
浏览 17

显示帖子总数

I wanna show count of total number of posts. I am using following code to show table data.

<table>
    <tr>
    <th>Id</th>
    <th>title</th> 
    <th>com</th>
    <th>com1</th>
    </tr>
    <tr>
    <?php
        $limit=10;
        if(empty($_GET['p'])){
            $start=0;
        }else{
            $pi=$_GET['p'];
            $end=$pi*$limit;
            $start=$end-$limit;
        }
        if(!empty($_GET['s'])){
            $ss=$_GET['s'];
            $query="select * from sports where title like '%$ss%'";
        }else{
            $query="SELECT * FROM sports limit $start,$limit";
        }
        $result=mysqli_query($connect,$query);
        while($row=mysqli_fetch_assoc($result)){
    ?>
            <tr>
            <td><?php echo $row['id'] ?></td>
            <td><?php echo $row['title'] ?></td>
            <td><?php echo $row['com'] ?></td>
            <td><?php echo $row['com1'] ?></td>
            </tr>   
    <?php 
        }
    ?>
</table>

There are total 120 records inserted in my table. Please let me know how to display count of total number of posts and if new data is inserted in table then count will increase automatic.

I want to show count of total number of posts before starting of table.

  • 写回答

4条回答 默认 最新

  • douniang3866 2017-08-18 09:13
    关注

    just update this part of your code:

       <?php
        $count = 1; // here
        $result=mysqli_query($connect,$query);
        while($row=mysqli_fetch_assoc($result)){
    ?>
            <tr>
            <td><?php echo $count; // here ?></td>
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['title']; ?></td>
            <td><?php echo $row['com']; ?></td>
            <td><?php echo $row['com1']; ?></td>
            </tr>   
    <?php 
           $count++; // here
        }
    ?>
    

    and this part too:

    <tr>
    <th>#</th>
    <th>Id</th>
    <th>title</th> 
    <th>com</th>
    <th>com1</th>
    </tr>
    
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本