jeudi 8 mars 2018

How to embed html within while-loop to specify my result based on what data is returned

The code I've presented displays data (moduleID & moduleName) associated with a log in user. Presently it shows it in plain text. I want to implement a way to iterate through the values (Possibly if-else statement within loop) in order for the specific html code associated with each moduleID to be displayed on the screen when the user logs in.

Here is my homepageDemo.php

<?php
session_start();
//including the database connection file
include 'config.php';

$cuserID= $_SESSION['userID'];

//fetching data in descending order (lastest entry first)
//$result = mysql_query("SELECT * FROM users ORDER BY id DESC"); // mysql_query is deprecated
$result = mysqli_query($mysqli, "SELECT m.moduleID, m.moduleName
FROM modules m
JOIN courses c ON m.courseID = c.courseID
JOIN usersDemo u ON c.courseID = u.courseID
WHERE userID = '$cuserID'"); // using mysqli_query instead



        //while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array 
        while($res = mysqli_fetch_array($result)) {     
            echo "<tr>";
            echo "<td>"."<a>".$res['moduleID']."</a>"."</td>";
            echo "<td>"."<a>".$res['moduleName']."</a>"."</td>";
        }
        ?>

Here is the html code attached to the moduleID of IS4437

<div id="loader-wrapper">
            <div id="loader"><div id="loader1"> 
              </div> 
              </div>
        <p><a  onclick="IS4439Function()">IS4437</a></p>
        </div>

Here is the html code attached to the moduleID of IS4408

 <div id="loader-wrapper1">
            <div id="loader"><div id="loader1"> 
              </div> 
              </div>
        <p><a onclick="IS4408Function()">IS4408</a></p>
        </div>

My question, is do you have any insight or coding example of how you would embed html code within a if-else statement inside the while loop I have presented that would display a certain variable if attached to my user (in my case the moduleID)?

Thanks in Advance.

Aucun commentaire:

Enregistrer un commentaire