jeudi 20 avril 2017

Show boolean values bootstrap table checkbox column from mysql query

i`ve been looking this answer from a lot of websites , but i couldn't find anything, here is my cuestion: i have mysql table like this:

CREATE TABLE bd_grid.tbl_datatable (
`id`         int(10) NOT NULL auto_increment,
`name`       varchar(250) NOT NULL default '',
`email`      varchar(250) NOT NULL default '',
`mobile`     varchar(250) NOT NULL default '',
`start_date` timestamp DEFAULT CURRENT_TIMESTAMP,
`status`     TINYINT(1),
PRIMARY KEY  (`id`));

THE 'STATUS' COLUMN IS TO INSERT BOOLEAN VALUES (0,1),here's one example, how i insert the boolean values

INSERT INTO bd_grid.tbl_datatable(`name`,`email`,`mobile`,`status`) VALUES('Ricardo Alejandro Lopez Reyes','lopezr853@gmail.com','8443853097',true);

all of those values, i use bootstrap table to show them but, the way that i want show the values from the column 'STATUS' is by a checkbox column. if the value of 'STATUS ' is 0 the checkbox is unchecked, if the value of status is 1, the checkbox is check

        
        <script type="text/javascript">

            var $table = $('#table');

                $table.bootstrapTable({
                    url:'list-user.php',
                    search:true,
                    pagination: true,
                    buttonsClass: 'primary',
                    showFooter: true,
                    minimumCountColumns: 2,

                    columns: [{
                        field: 'id',
                        title: '#',
                        sortable: true
                    },{
                        field: 'name',
                        title: 'Nombre',
                        sortable: true
                    },{
                        field: 'email',
                        title: 'E-mail',
                        sortable: true
                    },{
                        field: 'mobile',
                        title: 'Celular',
                        sortable: true
                    },{
                        field: 'start_date',
                        title: 'Fecha Inicio',
                        sortable: true
                    },{
                        field: 'status',
                        title: 'Estatus',
                        checkbox: true,
                        checkboxEnabled: true
                    }]
                });
        </script>
        </BODY>
</HTML>

when i load my bootstrap table all the checkboxes are unchecked, i use this file to iterate all the data from mysql table

THIS IS THE FILE CALLED:list-user.PHP,THAT THE BOOTSRAP TABLE USE TO LOAD THE INFORMATION, the conditional if ($rowList['status'] == 1) { I WANT TO CHANGE THE STATUS OF MY CHECKBOX TO CHECKED , AND FINALLY IN THE CONDITIONAL ELSE, CHANGE THE STATUS OF MY CHECKBOX TO UNCHECKED, BUT I REALLY DON`T NOW HOW TO MANIPULATE THE 'STATUS' COLUMNS TO CHANGE THE CHECKBOX

<?php
require 'db.php';

$sqltran = mysqli_query($con, "SELECT * FROM tbl_datatable ")or die(mysqli_error($con));
$arrVal = array();

$i=1;
while ($rowList = mysqli_fetch_array($sqltran)) {

    $name = array(
        'id' => $i,
        'name'=> $rowList['name'],
        'email'=> $rowList['email'],
        'mobile'=> $rowList['mobile'],
        'start_date'=> $rowList['start_date'],
        'status'=> $rowList['status']


    );

    if ($rowList['status'] == 1) {
        
        
        // CODE TO CHANGE THE STATUS OF THE CHECKBOX TO checked
        
        array_push($arrVal, $name);
        $i++;
    }

    else {
        
        // CODE TO CHANGE THE STATUS OF THE CHECKBOX TO unchecked
        array_push($arrVal, $name);
        $i++;
    }

}
echo  json_encode($arrVal);


mysqli_close($con);
?>



Aucun commentaire:

Enregistrer un commentaire