English 中文(简体)
• 如何正确地将变数引入下降的菜单
原标题:How to put variable in dropdown menu correctly

我有一个称为“单元”的变量。 我下班机的超文本录制,从一门课程中产出所有模块。 E.g. 课程:信通技术、模块:网络规划、现代数据库应用、电子商务。

现在,当我产出圆形超文本时,它就非常完美,因为它从该课程中将所有单元都投入使用。 但是,如果我尝试用美元来支付摩苏尔。 在下降的菜单中,只有一个模块作为减少菜单(即网络规划)的一种选择产出。 我怎样才能执行,以便把多个模块作为减少菜单的多种选择?

Below is code:

<?php
$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 =  ".mysql_real_escape_string($courseid)." )
                     ORDER BY c.CourseName, m.ModuleId";

$num = mysql_num_rows($result = mysql_query($query));
$dataArray = array();

while ($row = mysql_fetch_array($result)) { 
    $dataArray[$row[ CourseId ]][ CourseName ] = $row[ CourseName ]; 
    $dataArray[$row[ CourseId ]][ Modules ][$row[ ModuleId ]][ ModuleName ] = $row[ ModuleName ]; 
}

foreach ($dataArray as $courseId => $courseData) {
    $output = ""; 
    $output .= "<p><strong>Course:</strong> " . $courseId .  " - "  . $courseData[ CourseName ] . "</p>";

    foreach ($courseData[ Modules ] as $moduleId => $moduleData) { 
        // elaborate module data 
        $moduleHTML = "";
        $moduleHTML .= "<p>" . $moduleId . " - " . $moduleData[ ModuleName ] ."</p>"; 
         $output .= $moduleHTML;
    }
}

echo $output;
?>


<form action="create_session.php" method="post" name="sessionform">
   <table>
     <tr>
        <th>7: Module:</th>
        <td><select name="module" class="modulesDrop">
             <option value=""><?php echo $moduleHTML; ?></option>
     </tr>
   </table>
</form>
最佳回答

You have to do it in the same way:

$output =  <select name="module" class="modulesDrop"> .PHP_EOL;
foreach ($courseData[ Modules ] as $moduleId => $moduleData) { 
             $output .= "<option value=".$moduleId.">".$moduleData."</option>".PHP_EOL;
         }
     }
$output .=  </select> ;

如果出现下降:

问题回答

Every module should have it s own option. You re putting the full HTML into one option now.

有了简单的通道,你就可以通过所有模块,并将这些模块放在各种选择中......,将其放在<条码>上。

foreach ($courseData[ Modules ] as $moduleId => $moduleData) { 
  echo  <option value=""> .$moduleId.  -  .$moduleData[ ModuleName ]. </option> ; 
}

This way you will get an option for every module looped through.

for for create create create create 每个模块的要素:

foreach ($dataArray as $courseId => $courseData) 
{
    foreach ($courseData[ Modules ] as $moduleId => $moduleData) 
    {
        echo  <option value="  . $moduleId .  ">  . $moduleData[ ModuleName ] .  </option> ;
    }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签