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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用GROUP_CONCAT和EXPLODE函數(shù)在復(fù)選框中顯示?

如何使用GROUP_CONCAT和EXPLODE函數(shù)在復(fù)選框中顯示?

PHP
BIG陽 2023-08-11 10:55:51
我是 PHP 新手。所以我這里有幾個問題:所以,這是我的“item_choice”表:╔══════════╦═════════╦═══════════════╗║  c_id    ║ item_id ║ choice_name   ║╠══════════╬═════════╬═══════════════╣║   1      ║ 100     ║   Set A       ║║   2      ║ 100     ║   Set B       ║║   3      ║ 100     ║   Set C       ║║   4      ║ 100     ║   Set D       ║               ╚══════════╩═════════╩═══════════════╝這是我的“item_subchoice”表:╔══════════╦═════════╦═══════════════╦═══════════════╗║  sc_id   ║ c_id    ║    option     ║    price      ║╠══════════╬═════════╬═══════════════╬═══════════════╣║   1      ║   1     ║   Fries       ║      4        ║║   2      ║   1     ║   Coleslaw    ║      4        ║║   3      ║   1     ║ Mac n Cheese  ║      5        ║║   4      ║   2     ║   Fries       ║      4        ║               ╚══════════╩═════════╩═══════════════╩═══════════════╝到目前為止,這是我的結(jié)果(方形的東西是復(fù)選框):Set A:╔═╗  ╚═╝ Fries,Coleslaw,Mac n Cheese  4,4,5我想要實現(xiàn)的目標(biāo):Set A:╔═╗  ╚═╝ Friese  4,╔═╗  ╚═╝ Coleslaw  4╔═╗  ╚═╝ Mac n Cheese 5這是我當(dāng)前的代碼:<div class="form-row">    <?php    if (isset($_GET['itemid'])) {        $choice_id = $_GET['itemid'];        $get_choice_id = "SELECT                            t1.*,                             GROUP_CONCAT(t2.sc_id) AS sc_ids,                            GROUP_CONCAT(t2.option) AS choice_options,                            GROUP_CONCAT(t2.price) AS choice_prices                          FROM                             item_choice t1                           LEFT JOIN item_subchoice t2 ON t2.c_id = t1.c_id                           GROUP BY t1.c_id";        }    }    ?></div>我也嘗試過explode函數(shù)和array_merge,但我無法讓它工作。提前致謝!
查看完整描述

1 回答

?
不負(fù)相思意

TA貢獻1777條經(jīng)驗 獲得超10個贊

您可能可以只進行正常的選擇,并按集合排序 - 然后在循環(huán)結(jié)果時檢查 PHP 中的集合是否已更改。


另請注意,addon-checkbox不能是這樣的 ID,因為它不是唯一的 - 可以有多行,并且元素的 ID 必須是唯一的。


$current_set = null;

$query = $con->query("SELECT ic.*, isc.sc_id, isc.option, isc.price

                        FROM item_choice AS ic

                        LEFT JOIN item_subchoice AS isc 

                            ON ic.c_id = isc.c_id

                        ORDER BY ic.choice_name");

while ($row = $query->fetch_assoc()) {

    if ($current_set != $row['choice_name']) {

        $current_set = $row['choice_name'];

        echo '<h1>'.$current_set.'</h1>';

    }

    ?>

    <div class="form-group col-md-12">

        <hr style="height: 1px;">

        <label style='font-size:15px;'> Add Ons - <?= $row['choice_name'] ?>: </label>

    </div>

    <div class="form-group col-md-12">

        <input type="checkbox addon-checkbox" name='check_list[]' onclick="check(this)" value="<?= $row['sc_ids'] ?>" />

        <label><?= $row['choice_options'] ?> + <?= $row['choice_prices'] ?></label>

    <?php

}


查看完整回答
反對 回復(fù) 2023-08-11
  • 1 回答
  • 0 關(guān)注
  • 145 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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