Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:51:12+00:00 2026-06-13T02:51:12+00:00

I have code below where the user types in a Course, then it will

  • 0

I have code below where the user types in a “Course”, then it will display the relevant modules which belongs to that particular course and then it will display a drop down menu which belongs to the selected module.

The problem is that it only displays one session in the drop down menu which belongs to the module, even though there are a many sessions under that particular module.

For example is below is the database “Session” Table:

Session Table:

SessionId SessionDate SessionTime ModuleId
AAA       2012-10-19  09:00:00    CHI2513
AFD       2012-10-29  10:00:00    CHI2513
TPP       2012-09-11  09:00:00    CHI2513
NUM       2012-05-03  11:00:00    CHI2513

Then when the user selects Module “CHI2513” from the Module drop down menu, then in the Session drop down menu it should display the following option:

Session Drop Down menu:

AAA       2012-10-19  09:00:00
AFD       2012-10-29  10:00:00
TPP       2012-09-11  09:00:00
NUM       2012-05-03  11:00:00

But instead it is only showing one session in the drop down menu like below:

Session Drop Down menu it is showing at moment:

TPP       2012-09-11  09:00:00

So how can I display ALL of the sessions in the drop down menu which are relevant to the selected module?

Below is the code:

<?php
  if (isset($_POST['submit'])) {

    $query = "
             SELECT cm.CourseId, cm.ModuleId, 
             c.CourseName,
             m.ModuleName
             FROM Course c
             INNER JOIN Course_Module cm ON c.CourseId = cm.CourseId
             JOIN Module m ON cm.ModuleId = m.ModuleId
             WHERE
             (c.CourseId = ?)
             ORDER BY c.CourseName, m.ModuleId
            ";

$qrystmt=$mysqli->prepare($query);
// You only need to call bind_param once
$qrystmt->bind_param("s",$courseid);
// get result and assign variables (prefix with db)

$qrystmt->execute(); 

$qrystmt->bind_result($dbCourseId,$dbModuleId,$dbCourseName,$dbModuleName);

 $qrystmt->store_result();

$num = $qrystmt->num_rows();

if($num ==0){
    echo "<p>Sorry, No Course was found with this Course ID '$courseid'</p>";
} else { 

    $dataArray = array();

 while ( $qrystmt->fetch() ) { 
      // data array
      $dataArray[$dbCourseId]['CourseName'] = $dbCourseName; 
      $dataArray[$dbCourseId]['Modules'][$dbModuleId]['ModuleName'] = $dbModuleName; 
       // session data
      $_SESSION['idcourse'] = $dbCourseId;
      $_SESSION['namecourse'] = $dbCourseName;

}

 foreach ($dataArray as $courseId => $courseData) {

      $output = ""; 

      $output .= "<p><strong>Course:</strong> " . $courseId .  " - "  . $courseData['CourseName'] . "</p>";

   $moduleHTML = ""; 
   $moduleHTML .= '<select name="modulesDrop" id="modulesDrop">'.PHP_EOL;
   $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;      
        foreach ($courseData['Modules'] as $moduleId => $moduleData) {        

        $moduleHTML .= "<option value='$moduleId'>" . $moduleId . " - " .   
    $moduleData['ModuleName'] ."</option>".PHP_EOL;        
  } 
        }
        $moduleHTML .= '</select>';

  echo $output;


    ?>

     <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
     <p>Module: <?php echo $moduleHTML; ?><input id="moduleSubmit" type="submit" value="Submit" name="modulesubmit" /></p>      
    </form> 



    <?php
}
}

$sessionnum = 0;

 if (isset($_POST['modulesubmit'])) {

     if($_REQUEST['modulesDrop']==''){

         echo "Please Select a Module from the Drop Down Menu Above";

     }
     else{  

 var_dump($_POST['modulesDrop']);

        $sessionquery = "
             SELECT SessionId, SessionDate, SessionTime, ModuleId
             FROM Session
             WHERE
             (ModuleId = ?)
             ORDER BY SessionDate, SessionTime 
            ";

$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modulesDrop']);
// get result and assign variables (prefix with db)

$sessionqrystmt->execute(); 

$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId);

 $sessionqrystmt->store_result();

$sessionnum = $sessionqrystmt->num_rows();   

    $dataArraySession = array();

 while ( $sessionqrystmt->fetch() ) { 

 $dataArraySession[$dbSessionId]['SessionDate'] = $dbSessionDate; 
 $dataArraySession[$dbSessionId]['SessionTime'] = $dbSessionTime;

}

foreach ($dataArraySession as $sessionId => $sessionData) {



   $sessionHTML = ""; 
   $sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
   $sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;           
   $sessionHTML .= "<option value='$sessionId'>" . $sessionId . " - " . $sessionData['SessionDate']. " - " . $sessionData['SessionTime'] ."</option>".PHP_EOL;        

        }

   $sessionHTML .= '</select>';
}
 if ($sessionnum > 0) {

 ?>

     <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
     <p>Sessions: <?php echo $sessionHTML; ?><input id="sessionSubmit" type="submit" value="Submit" name="sesionsubmit" /></p>      
    </form>       

<?php

}
else {
 echo "<p>Sorry, You have No Sessions under this Module</p>";
}

}


    ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:51:13+00:00Added an answer on June 13, 2026 at 2:51 am

    Well You are applying an ORDER BY clause to your query, which says to me the TPP row of data is the last bit of data output by the query. Which then in turn tells me to look at your loop thats building the HTML output.

    In that loop you have $output = ""; in the begining of the loop. Which is reseting it every pass of the loop. And you do the same thing with $moduleHTML

    So I can see how $output being echoed at the end of every loop through will show the results correctly. But in the form below your calling modelHTML which for every loop through the results is resetting thus negating the concept of .= to append to it. What you should do is put

    $moduleHTML outside of your foreach so its initially defined there, then keep everything else the same.

    eg:

    $moduleHTML = "";
    foreach(....){.....}
    

    instead of

    foreach(....){....$moduleHTML = "";....}
    

    What its doing currently is only saving the last run so to speak through the loop for output in your widget, module, form, whatever..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below on form so that the user submits the form
Below I have a line of code where it states which Session a user
I have code that looks more or less like the code below but it
I have the code below which I use clone() and live() . The code
I have the following code which throws an exception (detail in code comments below).
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have code as below: var s : String = hello world var xml
I have the code below. It looks long and complicated and now I have
I have the code below. void *timer1_function(void * eit); pthread_t timer1; int thread_check1 =
I have this code below. I need to use a class id instead of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.