如何使用explode从php中的数据库中检索复选框值

时间:2016-09-26 07:24:18

标签: php html

我创建了一个表单,其中ii以三种形式放置了三个复选框,有些人检查了所有主题,有些只选择了两个主题,我想从数据库中检索复选框值。我已经提供了我当前的代码。如果有人知道解决方案,请告诉

     if (remoteMessage.getData().size() > 0) {
        Log.i("Message data payload: ", String.valueOf(remoteMessage.getData().toString()));

        notification_type = remoteMessage.getData().get("type");
        switch (notification_type){
            case "store":
                store_id = String.valueOf(remoteMessage.getData().get("store_id"));
                image_url = String.valueOf(remoteMessage.getData().get("url"));
                Log.i("prrr",store_id+"XCx"+String.valueOf(remoteMessage.getData().get("store_id")));
//                    message = String.valueOf(remoteMessage.getData().get("message"));
                    break;
                case "product":
                    product_id = String.valueOf(remoteMessage.getData().get("product_id"));
                    Log.i("prrr",product_id+"XCx"+String.valueOf(remoteMessage.getData().get("product_id")));
                    store_id = String.valueOf(remoteMessage.getData().get("store_id"));
                    image_url = String.valueOf(remoteMessage.getData().get("url"));
//                    message = String.valueOf(remoteMessage.getData().get("message"));
                    break;
                case "category":
                    category_id = String.valueOf(remoteMessage.getData().get("category_id"));
                    store_id = String.valueOf(remoteMessage.getData().get("store_id"));
                    Log.i("prrr",store_id+"XCx"+String.valueOf(remoteMessage.getData().get("store_id")));
                    Log.i("prrr",category_id+"XCx"+String.valueOf(remoteMessage.getData().get("category_id")));
                    image_url = String.valueOf(remoteMessage.getData().get("url"));
//                    message = String.valueOf(remoteMessage.getData().get("message"));
                    category_name = String.valueOf(remoteMessage.getData().get("category_name"));
                    break;

        }


    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.i("Message No: " ,"h"+remoteMessage.getNotification().getBody());
        title = remoteMessage.getNotification().getBody();
    }

    sendNotification(String.valueOf(remoteMessage.getData().get("url")));

1 个答案:

答案 0 :(得分:1)

试试这个

<?php
 $connection = mysql_connect("localhost", "root", "");
 $db = mysql_select_db("db_new", $connection);

 $query=mysql_query("SELECT * FROM student_info where id=17");
 $row= mysql_fetch_row($query);
 $rollno = $row[1];
 $name = $row[2];
 $division= $row[3];
 $std = $row[4];
 $gender = $row[5];
 $subject=mysql_query("select * from student_info where id=17");
 while($fetch=mysql_fetch_object($subject))
 {
   $r=$fetch->subject;
   $i=explode(",",$r);

 }
 mysql_close($connection);
?>

在复选框内,您可以使用in_array

进行检查
    <label><b>Subject:</b></label><br>
    <input type="checkbox" name="box[]" class="subject" value="maths" <?php if (in_array("maths", $i)){  echo "checked";}?>>maths<br>
    <input type="checkbox" name="box[]" class="subject" value="science" <?php if (in_array("science", $i)){  echo "checked";}?>>science<br>
    <input type="checkbox" name="box[]" class="subject" value="english" <?php if (in_array("english", $i)){  echo "checked";}?>>english<br>