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 8881697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:48+00:00 2026-06-14T20:23:48+00:00

I don’t think I am writing the code below correctly but I want to

  • 0

I don’t think I am writing the code below correctly but I want to be able to retrieve the value from the module drop down menu on another page. Below is the code where it contains a blank drop down menu and outputs the number and name of the module selected:

$sql = "SELECT CourseId, CourseNo, CourseName FROM Course"; 

 $sqlstmt=$mysqli->prepare($sql);

 $sqlstmt->execute(); 

 $sqlstmt->bind_result($dbCourseId, $dbCourseNo, $dbCourseName);

 $courses = array(); // easier if you don't use generic names for data 

 $courseHTML = "";  
 $courseHTML .= '<select name="courses" id="coursesDrop" onchange="getModules();">'.PHP_EOL; 
 $courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

 while($sqlstmt->fetch()) 
 { 
     $courseno = $dbCourseNo;
     $course = $dbCourseId;
     $coursename = $dbCourseName; 
     $courseHTML .= "<option value='".$course."'>" . $courseno . " - " . $coursename . "</option>".PHP_EOL;  
  } 

  $courseHTML .= '</select>'; 

    $moduleHTML = "";  
        $moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL; 
        $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  
        $moduleHTML .= '</select>'; 


        ?>

        <script type="text/javascript">

        function getModules() { 
        var course = jQuery("#coursesDrop").val(); 
        jQuery('#modulesDrop').empty(); 
        jQuery('#modulesDrop').html('<option value="">Please Select</option>'); 
        jQuery.ajax({ 
        type: "post", 
        url:  "module.php", 
        data: { course:course }, 
        success: function(response){ 
        jQuery('#modulesDrop').append(response); 
        } 
        }); 


        }


        </script> 

    <?php

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

    $outputmodule = ""; 

    $moduleInfo = explode("_", $_POST['modules']);
    $moduleId = $moduleInfo[0];
    $moduleNo = $moduleInfo[1];
    $moduleName = $moduleInfo[2];
    $outputmodule = sprintf("<p><strong>Module:</strong> %s - %s</p>", $moduleNo, $moduleName);

    ....

    ?>

Below is the module.php page where it displays the module number and name in the drop down menu depending on the course selected:

<?php

$course = isset($_POST['course']) ? $_POST['course'] : ''; 

    $sql = "
    SELECT cm.CourseId, cm.ModuleId, c.CourseNo, m.ModuleNo,
    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.CourseId, m.ModuleId
    "; 

     $sqlstmt=$mysqli->prepare($sql);

     $sqlstmt->bind_param("s",$course);

     $sqlstmt->execute(); 

     $sqlstmt->bind_result($dbCourseId,$dbModuleId,$dbCourseNo,$dbModuleNo,$dbCourseName,$dbModuleName);


    $moduleHTML  = "";  

     while($sqlstmt->fetch()) { 
         $moduleHTML .= sprintf('<option value="%1$s">%2$s - %3$s</option>'.PHP_EOL, $dbModuleId, $dbModuleNo, $dbModuleName);
    } 


    echo $moduleHTML; 

     $sqlstmt->execute(); 
    ?>

At the moment nothing is being displayed in the drop down menu except for the “Please Select” option

UPDATE:

Ok if you look at the editsessionteacher.php script, it contained the code below which worked:

$outputmodule = ""; 

        $moduleInfo = explode("_", $_POST['modules']);
        $moduleId = $moduleInfo[0];
        $moduleName = $moduleInfo[2];
        $outputmodule = sprintf("<p><strong>Module:</strong> %s - %s</p>", $moduleId, $moduleName);

The module.php was this:

$course = isset($_POST['course']) ? $_POST['course'] : ''; 

$sql = "
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.CourseId, m.ModuleId
"; 

 $sqlstmt=$mysqli->prepare($sql);

 $sqlstmt->bind_param("s",$course);

 $sqlstmt->execute(); 

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


$moduleHTML  = "";  

     while($sqlstmt->fetch()) { 
         $moduleHTML .= sprintf('<option value="%1$s_%2$s">%1$s - %2$s</option>'.PHP_EOL, $dbModuleId, $dbModuleName);
    } 


echo $moduleHTML; 

 $sqlstmt->execute();

But I want to add the moduleNo into the drop down menu, so when I tried to change the code to this below, it doesn’t work:

editsessionteacher.php:

$outputmodule = ""; 

$moduleInfo = explode("_", $_POST['modules']);
$moduleId = $moduleInfo[0];
$moduleNo = $moduleInfo[1];
$moduleName = $moduleInfo[2];
$outputmodule = sprintf("<p><strong>Module:</strong> %s - %s</p>", $moduleNo, $moduleName);

module.php:

    $course = isset($_POST['course']) ? $_POST['course'] : ''; 

    $sql = "
    SELECT cm.CourseId, cm.ModuleId, c.CourseNo, m.ModuleNo,
    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.CourseId, m.ModuleId
    "; 

     $sqlstmt=$mysqli->prepare($sql);

     $sqlstmt->bind_param("s",$course);

     $sqlstmt->execute(); 

     $sqlstmt->bind_result($dbCourseId,$dbModuleId,$dbCourseNo,$dbModuleNo,$dbCourseName,$dbModuleName);


    $moduleHTML  = "";  

$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL; 
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

 while($sqlstmt->fetch()) { 
     $moduleHTML .= sprintf('<option value="%1$s">%2$s - %3$s</option>'.PHP_EOL, $dbModuleId, $dbModuleNo, $dbModuleName);
} 

$moduleHTML .= '</select>'; 

echo $moduleHTML; 
  • 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-14T20:23:49+00:00Added an answer on June 14, 2026 at 8:23 pm

    It appears that you never call the javascript function getModules() that would make the request to get new options. Try adding this within your <script> tag:

    jQuery(function(){
      jQuery("#coursesDrop").change(getModules); 
    
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know why, but this code worked for me a month ago... maybe
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know where else to ask, but from one day to the other my
Don't know if I worded the question right, but basically what I want to
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't think there's much to say, here's my code for (int i = 0;
Don't get me wrong, I want them to get saved. But I always thought
Don't know why it's not working, i think the code is fine - could
don't know better title for this, but here's my code. I have class user
Don't know how to frase this but I found this code wich works as

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.