如何在php中显示来自数据库的多个复选框值

mec1mxoz  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(289)

请看数据库的图片也我想显示我的复选框值从数据库。

Example : my value is 25,26.
So, How can i display it one by one ?
such as,
-- 1st value is : 25.
--2nd Value is : 26.

我的代码:

$db = new mysqli("localhost","paroshic_paroshic","kxmcwQzLTrTR","paroshic_matri2018jl");
    $sql = "select * from tbldatingusermaster order by userid desc";
    $result = $db->query($sql);

    while($data = $result->fetch_object()){
    echo $data->education; //My value is 25,26

}
谢谢。

3pmvbmvn

3pmvbmvn1#

你知道,你可以用echo把html标记写到页面上。所以基本上是这样的:

while($data = $result->fetch_object()){
    echo '<input type="checkbox" name="check" value="'.$data->educationid.'">'.$data->educationid.'<br>';
}
5fjcxozz

5fjcxozz2#

我想你要找的那块拼图可能是 explode 从给定字符串创建整数数组 $data->educationid (即:25,26)

$db = new mysqli("localhost","paroshic_paroshic","kxmcwQzLTrTR","paroshic_matri2018jl");
$sql = "select * from tbldatingusermaster order by userid desc";
$result = $db->query( $sql );

if( $result ){
    while( $data = $result->fetch_object() ){
        /* explode the string into little integers */
        $ids=explode( ',', $data->educationid );

        /* iterate through the pieces and generate an input[checkbox] element */
        foreach( $ids as $id )printf('<input type="checkbox" name="UNKNOWN[]" value="%s" />',$id);
    }
}

相关问题