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

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

如何在php中顯示數(shù)據(jù)庫(kù)中選中的復(fù)選框?

如何在php中顯示數(shù)據(jù)庫(kù)中選中的復(fù)選框?

PHP
浮云間 2021-09-05 20:52:29
我想顯示已選中的復(fù)選框,這些復(fù)選框作為值存儲(chǔ)在 mysql 數(shù)據(jù)庫(kù)中?,F(xiàn)在,該表存儲(chǔ)在數(shù)據(jù)庫(kù)中選中的復(fù)選框的值。標(biāo)題和第一列是從數(shù)據(jù)庫(kù)中的三個(gè)不同表中獲取的。選中復(fù)選框的值保存在同一個(gè)表中。這是插入數(shù)據(jù)的代碼。$active = "CourseReport";require_once 'pages/header.php';require_once './functions/schema-functions.php';require_once './functions/report-functions.php';$course = Schema::getCourseReport();$objective = Schema::getObjective();$goals = Schema::getGoals();$mainobj = Schema::getMainObjectives();$subobj = Schema::getSubObjectives(); ?><form id="addReport" action ='./functions/report-functions.php' method="post"><table id="table1" class="table table-hover">    <thead>    <?php    echo '<tr><th>Goals</th>';    for ($i = 0; $i < count($course); $i++) {        echo '<th id = "rotate1">'. $course[$i]->commonName . '</th>';                }    echo '</tr>';       ?>    </thead>        <tbody>    <?php    for ($y = 0; $y < count($goals); $y++) {                   echo '<tr class="clickable"><th class="toggle">Goal#'.$goals[$y]['GoalId'].':'." " .' '.$goals[$y]['Goals'].'</th>        </tr>';              ?>    <?php    for( $z = 0; $z < count($mainobj); $z++){  if($mainobj[$z]['GoalId'] == $goals[$y]['GoalId']) {        echo '<tr class="expander"><th class=row-header>Objective#'.$mainobj[$z]['MainObjId'].':'." ".' '.$mainobj[$z]['MainObjectives'].'</th>    </tr>';     ?>    <?php    for ($j = 0; $j< count($subobj); $j++) {       if($mainobj[$z]['MainObjId'] == $subobj[$j]['MainObjId']){       echo '<tr class="expander"><td class=row-header>'.$subobj[$j]['SubObjId'].' ) '.$subobj[$j]['SubObjectives'].' </td>';   for ($x = 0; $x < count($course); $x++) {      echo "<td><input name='check[]' type=checkbox value=c".$course[$x]->courseId."-o".$subobj[$j]['SubObjId']." id=checked></td>";        }        echo '</tr>';    }   }  } }}           ?>               </tbody>       </table><button class="button" name= "submit" value= "Submit">Submit</button></form>
查看完整描述

1 回答

?
慕田峪4524236

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

當(dāng)您顯示您的頁(yè)面(在您的第一段代碼中)時(shí),您有時(shí)會(huì)這樣做:


echo "<td><input name='check[]' type=checkbox value=c".$course[$x]->courseId."-o".$subobj[$j]['SubObjId']." id=checked></td>";

該值設(shè)置為:


value=c"c.$course[$x]->courseId."-o".$subobj[$j]['SubObjId']";

該值是您在評(píng)論中提到的選中或未選中的值(如c1-o1.1)。


對(duì)。所以在你這樣做之前echo,添加一個(gè)新的if條件。


$value = "c$course[$x]->courseId" . "-o$subobj[$j]['SubObjId']";

if (verify_checked($value)) {

    $checked_code = "checked=\"checked\"";

}

else {

    $checked_code = "";

}

echo "<td><input name='check[]' type=checkbox value=$value id=checked $checked_code ></td>";

該verify_checked(value)函數(shù)執(zhí)行(根據(jù)我對(duì)您的數(shù)據(jù)庫(kù)的了解,您保留已檢查元素的“網(wǎng)格位置”):


function verify_checked($value)

{

    // Connect to the database if needed

    // Perform: SELECT count($value) FROM Report

    // If the result is >0, return TRUE

    // Else return FALSE

}

這里的想法是在每次要回顯<input>元素時(shí)查詢數(shù)據(jù)庫(kù)。

連接文本的注意事項(xiàng),我發(fā)現(xiàn)在 周圍放置空格.以清楚地分割文本的一部分和連接點(diǎn)是更清晰的。

如前所述,縮進(jìn)對(duì)于理解不同的上下文至關(guān)重要。在我縮進(jìn)你的代碼之前,我還沒(méi)有意識(shí)到不同的循環(huán)是如何與其他循環(huán)相關(guān)的。



查看完整回答
反對(duì) 回復(fù) 2021-09-05
  • 1 回答
  • 0 關(guān)注
  • 218 瀏覽

添加回答

舉報(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)