显示帖子总数

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.

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>

If I got your question right, I think you can use the mysqli_num_rows to get the number of elements in your result set: Check here for reference: mysqli_result::$num_rows

After seeing your code I think you need to fire other query to get total number of records, where you are fetching data for pagination. I've updated code.

Hope it will be helpful.

<table>
<tr>
    <th>Id</th>
    <th>title</th> 
    <th>com</th>
    <th>com1</th>
</tr>
<tr>
<?php
    $limit=10;

    // Declared variable total
    $total = 0;
    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%'";
        $result=mysqli_query($connect,$query);

        //Get total number of records for search query
        $total=$result->num_rows;
    } else {
        // Get total number of records for pagination
        $totalQuery = "SELECT * FROM sports";
        $totalResult = mysqli_query($connect, $totalQuery);
        $total = $totalResult->num_rows;

        // Get page data
        $query = "SELECT * FROM sports limit $start,$limit";
        $result = mysqli_query($connect,$query);
    }

    // you can echo $total to display total records
    // anywhere you want

    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 
    }
?>

try this. write my code in between two of your query

 $result=mysqli_query($connect,$query);
 $count=mysqli_num_rows($result);//it will store your total selected row
 while($row=mysqli_fetch_assoc($result)){
 }