0

I tried echoing from the database and i am not getting any result

Whereas the sql query is running perfectly from phpmyadmin.

I don't know what is wrong here.

Here is my code

           <?php
            $result = mysqli_query($con, "SELECT * FROM exam INNER JOIN user ON 
            exam.department_id = user.department_id
            WHERE   user.login_id like 'I%%' And exam.display_exam = 'yes' 
            ORDER BY exam_id ASC") or die(mysqli_error($con));
            $row= mysqli_num_rows($result);

            if(mysqli_num_rows($result)>0){
            echo "there are rows";

            while($row = mysqli_fetch_array($result)){

            ?>

            <tr>
                <td class="line"> <?php echo $row['c_code']; ?> </td>
                <td class="line"> <?php echo date('m-d-Y', 
                 strtotime($row['exam_from'])) . ' - ' . date('m-d-Y', 
                 strtotime($row['exam_to'])); ?> </td>
                <td class="line"> <?php echo $row['exam_type'];?></td>
                <td class="line"> <?php echo $row['time_limit'] + 'minute(s)';?></td>
                <td class="line"> <?php echo $row['passing_score'];?></td>
                <td width="100" align="center" class="line1">
                    <a href="javascript:loadPage('index.php?
                 staff/examsresult&exam_id=<?php echo $row['exam_id'] ?>');"> View Result</a>
                </td>
            </tr>
            <?php
        }
    }  
akinlex
  • 23
  • 6
  • Have you tried to step through that code with a [debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems)? – litelite Nov 15 '17 at 15:16
  • 1
    Remove the following line `$row= mysqli_num_rows($result);` – Muaaz Khalid Nov 15 '17 at 15:26
  • This line `$row= mysqli_num_rows($result);` does not appear to do anything. – Adder Nov 15 '17 at 15:26
  • `I%%` and `I%` will give the same result. better to keep one %. Moreover, try to debug the code. – Muaaz Khalid Nov 15 '17 at 15:27
  • @Adder I know, I removed it still no results displayed – akinlex Nov 15 '17 at 15:28
  • I am pretty sure you don't include your connection anywhere. – pr1nc3 Nov 15 '17 at 16:04
  • Put `error_reporting(E_ALL);` in front of the code and tell us in which line the error is. – Adder Nov 15 '17 at 16:19
  • @pr1nc3 I am not a noob. I did that – akinlex Nov 15 '17 at 16:31
  • Go step by step. `print_r($result);` Is that ok? Then do you enter the if? Then print some debug message every time you enter the while. Then `print_r($row);` in the while to ensure your row is what you expect. Baby steps, until you find the problem. The actual cause is not flagrant from what you posted. – Nic3500 Nov 15 '17 at 17:13

0 Answers0