0

I need to show the posts count depend on topic id using auto load jquery load() after looping the result using php but unfortunately it shows the first row and uses that first row to show another count and change again Any Help please!


index.php

    <?php
    foreach($t_all_rows as $row){
            ?>
         <tr>
             <td class="text-center hidden-xs hidden-sm">
                 <a class="font-w600" href="javascript:void(0)">
                    <script type="text/javascript">
                                    var auto_refresh = setInterval(
                                    function ()
                                    {
            $('#load_posts').load('get_posts.php?t_id=<?php echo $row['t_id']; ?>').fadeIn("slow");
                                    }, 1000); // refresh every 5000 milliseconds
                                    </script>

                                   <span id="load_posts"></span>
                </a>
          </td>
       </tr>
       <?php } ?>

get_posts.php

    include('connection.php');
    $db=new DB();
    $conn=$db->db_connect();
    $my_t_id=$_GET['t_id'];
    $post_query = mysqli_query($conn,'SELECT * FROM post WHERE t_id = "'.$my_t_id.'"');
    $record_count=mysqli_num_rows($post_query);
    //Display count.........
    echo $record_count;
0

2 Answers 2

1

that is normal, because get only first div by ID, change the span id or add a new class with loop number

Adding $k

    foreach($t_all_rows as $k =>  $row){

Adding new class

<span id="load_posts" class="load_post<?=$k?>"></span>

change jquery code:

$('.load_post<?=$k?>').load

But importan, I am suggest to you, to upgrate the mysql query using JOIN and not use jquery

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

Comments

0

Thanks for the help i finally realize i shoud use class instead of id

<script type="text/javascript">
                                var auto_refresh = setInterval(
                                function ()
                                {
        $('.load_posts<?php echo $index; ?>').load('get_posts.php?t_id=<?php echo $row['t_id']; ?>').fadeIn("slow");
                                }, 1000); // refresh every 5000 milliseconds
                                </script>

                               <span class="load_posts<?php echo $index; ?>"></span>

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.