0
<?php
      require("db.php");

      session_start();
      $id = $_SESSION["id"];

      $sql = "SELECT seguido FROM seguindo WHERE seguidor = '$id'";
      $result = $conn->query($sql) or die($conn->error);

      $posts = array();

      while($row = $result->fetch_assoc()){
        print_r($row);
        $id_seguindo = $row["seguido"];
        $sql = "SELECT imagem, descricao, tempo FROM posts WHERE id = '$id_seguindo' OR id='$id' ORDER BY tempo DESC";
        $result = $conn->query($sql) or die($conn->error);
        $row = $result->fetch_assoc();

        $posts[] = array(
            "imagem" => $row["imagem"],
            "descricao" => $row["descricao"],
            "tempo" => $row["tempo"]
        );
      }
      foreach($posts as $post){
          echo "<div class='post'>";
          echo "<img src='" . $post["imagem"] . "'>";
          echo "<p>" . $post["descricao"] . "</p>";
          echo "<p>" . $post["tempo"] . "</p>";
          echo "</div>";
      }

    ?>

For some reason, the while has become infinite and it is noticing that the "seguido" index is not defined. I don't know why this is happening and I've tried both the "isset" function and "print_r" to debug, but it didn't work.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • You are overwriting the value of `$row` and `$result` in your loop with this: `$result = $conn->query($sql) or die($conn->error); $row = $result->fetch_assoc();` You need to use different variable names inside the loop – Nick Jan 06 '20 at 03:48
  • I'm sorry, I misunderstood you. I tried something. Actually what you said was right, and it fixed my program. Thank you. – John Sandmann Jan 06 '20 at 04:02
  • @Nick Pardon my laziness, but do you know if the duplicate contains what you wrote in comments? If it doesn't, maybe you should add an example to the wiki. Edit: I don't think it does, I just checked. Maybe this question could serve as an example in it. – Funk Forty Niner Jan 06 '20 at 04:59
  • @FunkFortyNiner to be honest I was a bit lazy myself finding a duplicate I think there are probably better ones for this question. – Nick Jan 06 '20 at 05:02
  • @Nick *lol!* No worries :) Well listen... maybe you and I (and maybe others) could contribute to it but I wouldn't be a good starter for it right now. Using this question could be part of it too and pulling their code from it with a link back to here; hoping that they don't delete their question that is. Could be worth it; what have we got to lose? heh! Ping me if you do start one, and vice-versa. – Funk Forty Niner Jan 06 '20 at 05:04
  • @FunkFortyNiner will do. It is an interesting one and - having just looked carefully over the duplicate - it's not mentioned there. – Nick Jan 06 '20 at 05:16

0 Answers0