簡體   English   中英

在 Javascript 警報框中添加 COUNT

[英]Add COUNT in Javascript alert box

此頁面是用戶將 select 學期和課程的位置,然后將在所選課程上提示警報框,如下圖所示。

圖片

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    |                |
+---------------+------------------+------+-----+---------+--------------------+

您可以使用如下查詢返回每條記錄的計數:

SELECT student_prg, COUNT(student_prg) as count FROM marketing_data GROUP BY student_prg ORDER BY student_prg DESC

您的結果現在將計算每個student_prg值的數量。

然后我可能會將計數添加為您正在編寫的選項的數據屬性:

echo '<option value="'.$row['student_prg'].' data-count="'.$row['count'].'">'.$row['student_prg'].'</option>';

然后您可以 select 新選擇的選項中的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM