【发布时间】:2020-05-31 02:17:15
【问题描述】:
此页面是用户选择学期和课程的地方,然后警报框将提示所选课程,如下图所示。
Javascript
<script type="text/javascript">
$(document).ready(function(){
$("#prg").change(function(){
var selectedcount = $('#prg option:selected').data('count');
alert ("The next intake for " +selectedcount + " will have " + "students");
}); </script>
身体
<div class="modal-body">
<div class="form-group">
<label for="title">Select Current Semester:</label>
<select name="semester" class="form-control">
<option value="">--- Select Current Semester ---</option>
<?php
require('../setting/config.php');
$query = "SELECT DISTINCT semester FROM marketing_data ORDER BY semester DESC";
$do = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($do)){
echo '<option value="'.$row['student_matric'].'">'.$row['semester'].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="title">Select Programme:</label>
<select id="prg" name="prg" class="form-control">
<option value="">--- Select Programme ---</option>
<?php
$query2 = "SELECT student_prg, COUNT(student_prg) as count FROM marketing_data GROUP BY student_prg ORDER BY student_prg DESC";
$do = mysqli_query($conn, $query2);
while($row = mysqli_fetch_array($do)){
echo '<option value="'.$row['student_matric'].' data-count="'.$row['count'].'">'.$row['student_prg'].'</option>';
}
?>
</select>
我希望提醒框也添加学生人数。例如:*多媒体工业(荣誉)学士的下届入学将有 36 个学生*
您能否就在何处以及如何添加计数查询提供帮助,以便它会显示在我提到的警报框中。
数据库
mysql> describe marketing_data;
+---------------+------------------+------+-----+---------+--------------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+--------------------+
| student_matric| varchar(10) unsigned | NO | PRI | NULL | auto_increment |
| student_prg | text unsigned | YES | | NULL | |
| semester | varchar(10) | YES | | NULL | |
| intake_year | int(10) | YES | | NULL | |
| student_city | text | YES | | NULL | |
| city_lat | varchar(20) | YES | | NULL | |
| city_long | varchar(20) | YES | | NULL | |
| student_state | text | YES | | NULL | |
| state_code | varchar(100) | YES | | NULL | |
+---------------+------------------+------+-----+---------+--------------------+
【问题讨论】:
标签: javascript php html mysql