-3

This is the student who have a subject of National Service Training Program 1 and Physical Education 1 here is the code and picture

select en.*, su.descc from enrollment en inner join subject su on su.year = en.year

This is the picture

after that when the student logged in it only shows National Service Training Program 1 subject, how to display also the Physical Education 1?

This is the result when the student logged in

  <?php
session_start();
include_once("config.php");

if(!isset($_SESSION['sid'])){
            header("Location:index.php");
    }   
       // Subject
        $i=$_SESSION['sid'];
        $q=mysqli_query($mysqli,"SELECT en.*, su.descc FROM enrollment en INNER JOIN subject su ON 
        su.year = en.year
         WHERE id='$i'") or die (mysqli_error());
        $r=mysqli_fetch_array($q);

?>
<html>
         <body>
                   <h2> Subject: <?php echo $r['descc'];?> </h2>
                    <h2> Subject: <?php echo $r['descc'];?> </h2>
         </body>
</html>

EXPECTED OUTPUT This would be the Expected output when the student logged in Expected Output

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sanity
  • 23
  • 5
  • you need a loop (e.g while loop) – Ken Lee Dec 30 '20 at 04:09
  • @KenLee while ($res=mysqli_fetch_array($rs)) like this?? – Sanity Dec 30 '20 at 04:12
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Dec 30 '20 at 14:45
  • You have an error. [`mysqli_error()`](https://www.php.net/manual/en/mysqli.error.php) needs one argument. Please consider switching error mode on instead. [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) – Dharman Dec 30 '20 at 14:45

1 Answers1

-1

You need a loop (e.g while loop).

Please change your codes (for the body part) to

<body>
<?php while ($r=mysqli_fetch_array($q)){ ?>
                   <h2> Subject: <?php echo $r['descc'];?> </h2>

<?php } ?>

         </body>
</html>
Ken Lee
  • 6,985
  • 3
  • 10
  • 29