簡體   English   中英

根據單選按鈕過濾記錄

[英]Filter records based on radio button selection

我正在創建一個表單,其中將基於對單選按鈕的選擇生成一個下拉列表。

表格圖片

日記帳名稱存儲在類型為1或2的表中。當選擇單選按鈕“日記帳”時,日記帳類型的過濾器將為1,其他過濾器將為2。我正在使用以下代碼來生成表格。

<?php 
    $ctype = 1 // $ctype created for filtering purpose
?>

<p> Article For: 
    Journal <input type="radio" name="article_for" value="Journal" id="article_journal" /> 
    Conference <input type="radio" name="article_for" value="Conference" id="article_conference" />
</p>

<?php
    // $ctype will depend upon selection from radio button. If selection is "Journal"
    // value of $ctype to set 1 otherwise to set 2.
    $selectrecord = "SELECT `content_id`, `content_type`, `content_name` FROM `content` where `content_type` = $ctype";
    $result = mysqli_query($connection,$selectrecord) or die(mysqli_error($connection));
?>

<p> Journal Name: 
    <select name='content_id'>
        <?php
            while ($row = $result->fetch_assoc()) {
                unset($id, $name);
                $id = $row['content_id'];
                $name = $row['content_name']; 
                echo '<option value="'.$id.'">' . $name . '</option>';
            }
        ?>
    </select>
</p>

我可以使用如下代碼集檢查選中的單選按鈕

if(document.getElementById('article_journal').checked) {

但是在此if子句中,我無法為變量$ ctype分配值-該變量用於過濾下拉列表的名稱。

請幫助我找出我做錯了什么。

最好的祝福。

最終,我決定創建多個頁面,其中相關字段在物理上距離很遠。 POST變量解決了該問題。 它們彼此相鄰的地方,我使用jQuery來過濾選項。

暫無
暫無

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

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