Pregunta

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.

¿Fue útil?

Solución

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'];
        }
    }
?>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top