第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP/MYSQLI 如何從表單內(nèi)的 while 循環(huán)返回變量以在該表單的操作/方法中的 $_GET

PHP/MYSQLI 如何從表單內(nèi)的 while 循環(huán)返回變量以在該表單的操作/方法中的 $_GET

PHP
倚天杖 2023-04-21 16:48:21
我有一個(gè) html 表單,它使用 PHP while 循環(huán)從 MYSQLi 數(shù)據(jù)庫(kù)填充選擇菜單。下面的代碼;$query = "SELECT on_programme, last_name, first_name, middle_name, id FROM constant_client WHERE on_programme=1 ";$result = mysqli_query($conn, $query);echo '<p><label for="current_clients">Select Client by name: </label>        <select id="current_clients" name="current_clients">        <option> -- Select Client -- </option>';        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {          echo '<option>'.ucwords($row['last_name']).', '.ucwords($row['first_name']).' '.ucwords($row['middle_name']).'</option>';        }echo '</select>'; 以上工作,表格填充了所需的客戶記錄。但是,然后我希望使用此數(shù)據(jù)鏈接到我嘗試使用的單個(gè)客戶端頁(yè)面echo '&emsp;<a href="selected_client.php?id='.$row['id'].'" onClick="this.form.submit()">Go!</a>';這不起作用,所以我嘗試將表單操作設(shè)置為action="selected_client.php?id='.$row['id'].'"方法為“GET”,也沒(méi)有用。正如您在查詢中看到的那樣,我也從表中選擇了“id”,因此稍后我可以調(diào)用數(shù)組的那部分,我只是不是特別需要或不想回顯它。使用表單操作方法時(shí),未設(shè)置 $row['id'] 變量,使用 onClick 方法時(shí),出現(xiàn)“嘗試訪問(wèn) null 類型值的數(shù)組偏移量”錯(cuò)誤。我想象需要在表單操作發(fā)生之前設(shè)置變量,但我想不出在不移動(dòng) while 循環(huán)或至少?gòu)闹蟹祷刂档那闆r下如何做到這一點(diǎn)。是否可以在提交時(shí)而不是在表單頂部調(diào)用表單方法和操作?那會(huì)有什么不同嗎?編輯; 根據(jù)要求,我嘗試對(duì)表單使用隱藏方法echo '<input type="submit" name="submit" value="Go!"><input type="hidden" name="id" value="'.$row['id'].'">';其中仍然返回空值類型的錯(cuò)誤。編輯 #2 - 所有代碼內(nèi)聯(lián)。$query = "SELECT on_programme, last_name, first_name, middle_name, id FROM constant_client WHERE on_programme=1 ";$result = mysqli_query($conn, $query);echo  '<form action="selected_client.php" method="get">    <fieldset>';echo '<p><label for="current_clients">Select Client by name: </label>        <select id="current_clients" name="current_clients">        <option> -- Select Client -- </option>';        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {          echo '<option>'.ucwords($row['last_name']).', '.ucwords($row['first_name']).' '.ucwords($row['middle_name']).'</option>';        }echo '</select>';echo '<input type="submit" name="submit" value="Go!"><input type="hidden" name="id" value="'.$row['id'].'">';echo '</fieldset></form>';
查看完整描述

1 回答

?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

添加 onChange 事件并將所選值傳遞給某個(gè)函數(shù),在該函數(shù)中使用該所選值設(shè)置隱藏字段?,F(xiàn)在您可以提交表單并可以接收您選擇的值。下面是解決方案。


$query = "SELECT on_programme, last_name, first_name, middle_name, id FROM constant_client WHERE on_programme=1";

$result = mysqli_query($conn, $query);

echo  '<form action="selected_client.php" method="get">

    <fieldset>';


echo '<p><label for="current_clients">Select Client by name: </label>

        <select id="current_clients" name="current_clients" onChange="setId(this.value);">

        <option value=""> -- Select Client -- </option>';


        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

          echo '<option value="'.$row['id'].'">'.ucwords($row['last_name']).', '.ucwords($row['first_name']).' '.ucwords($row['middle_name']).'</option>';

        }

echo '</select>';

echo '<input type="submit" name="submit" value="Go!">

<input type="hidden" name="id" id="hidden_field" value="">';


echo '</fieldset></form>';

添加此腳本以在隱藏字段中設(shè)置值。


<script>

function setId(rowValue){

   document.getElementById("hidden_field").value=rowValue;

}

</script>


查看完整回答
反對(duì) 回復(fù) 2023-04-21
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)