I am working on a property web site. They want to enter all specifications of the house or apartment. I want to fetch data from 1 database field.

Please check Example picture: http://i.stack.imgur.com/7XBEI.jpg

If value is like See in Cafe,YP Online then both See in Cafe & YP Online check boxes must be checked. This is only a Example Form, i have more than 100 checkboxes. I do not want to make 100 fileds only for checkboxes.

looking forward to your reply.

有帮助吗?

解决方案

Do you want to right database entry based on the checkboxes selected, or automatically highlight the checkboxes that are in the database as well?

<?php
    /*
    *   Assuming MySQLi initialized as $mysqli
    *   Assuming <input type="checkbox" name="checkbox[]" />
    */

    $found = array();

    foreach($_POST['checkbox'] as $checkbox) {
        if(!$s = $mysqli->query("SELECT `id`, `value` FROM `table` WHERE `value` LIKE '%$checkbox%'")) {
            // No result
        } else {
            $result = $s->fetch_assoc();
            $found[$result['id']] = $result['value'];
        }
    }
?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top