-2

I need help on some codes. This isn't made by me, i just copy a source code to make a website from another developer. I still don't know what is the problem although I have searched all the solutions online, because I am still learning.

<?php
       $limit = 5;
       $pagination = isset($_GET['pagination']) ? $_GET['pagination'] : "";

       if (empty($pagination)) {
            $position = 0;
            $pagination = 1;
       } else {
            $position = ($pagination - 1) * $limit;
       }

      $query = $connect->execute("SELECT pinjam.id_peminjaman, pinjam.id_user,
               user.nama_user, pinjam.id_ruang, ruang.nama_ruang, pinjam.id_hari,
               hari.nama_hari, pinjam.tgl_pinjam, pinjam.jam_awal, 
               pinjam.jam_akhir, pinjam.keterangan, pinjam.status
               FROM tbl_peminjaman AS pinjam
               LEFT JOIN tbl_user AS user ON pinjam.id_user = user.id_user
               LEFT JOIN tbl_ruang AS ruang ON pinjam.id_ruang = ruang.id_ruang
               LEFT JOIN tbl_hari AS hari ON pinjam.id_hari = hari.id_hari
               ORDER BY pinjam.updated_at DESC LIMIT $position, $limit");

      $no = 1 + $position;
      $check_search = $query->num_rows;
      while ($query->fetch_object()) {
          if ($data->status == 'DITERIMA') {
                   $color = "green-text";
          } elseif ($data->status == 'DITOLAK') {
                   $color = "red-text";
          } elseif ($data->status == 'MENUNGGU') {
                   $color = "yellow-text";
          } else {
                   $color = "grey-text";
          }
 ?>

Sorry, i haven't know yet how to modify the undetected variable. So please, help me. Thanks :)

Mehravish Temkar
  • 4,275
  • 3
  • 25
  • 44
KangBG
  • 1
  • 1
  • `while ($query->fetch_object())` no return value is utilized, its probably meant as `while ($data = $query->fetch_object())` – Kevin May 17 '19 at 02:13
  • Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) –  May 17 '19 at 02:13

1 Answers1

1

Change this line

while ($query->fetch_object()) {

to this

while ($data = $query->fetch_object()) {
user1178830
  • 436
  • 3
  • 11