0

Im doing a reservation site for a project.

And Im trying to disable radio button(s) if the sql statement returns true.

Example:
User selects a date and a time, and radio button(s) would be disable depending on database.

So far, I have this:

$result=mysqli_query($mysqli,"SELECT tableselect FROM reserve WHERE reserveDate = '". $date ."' AND reserveTime = '". $time ."'");
    if($row = $result->fetch_array(MYSQLI_ASSOC)){
        echo $row['tableselect'];
        if($t){?>
            //WHAT MUST BE HERE? 
        <?php
        }
    }

Doing it on PHP, JQuery. Please help?

3
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by broj1
0
$result=mysqli_query($mysqli,"SELECT reserv_id,tableselect FROM reserve WHERE reserveDate = '". $date ."' AND reserveTime = '". $time ."'");
$reserves = array();//php
$reserveJSArray = 'var reserveArray = {';
if($row = $result->fetch_array(MYSQLI_ASSOC)){
    echo $row['tableselect'];
    $i = 0;
    if($t){
        $reserves[$row['reserv_id']] = 1;
        //or
        if($i == 0){
            $tmpJS = $row['reserve_id'].': = 1';
            $i++;
        }else{
            $tmpJS .= ','.$row['reserve_id'].': = 1';
        }
    }
}
$reserveJSArray .= $tmpJS.'};';

The php version you just use a if(isset($reserves[$id]) && $reserves[$id] == 1){//disabled}

The JS version you print out the php var inside script tags then you loop through the array using jquery setting all the matching rows disabled(matching them by giving the element the reserv_id in its id eg. id='reser-234' '#reser-'+id)

0

I hope I got your question. You want to draw radio button which is either enabled or disabled, depending on a query result.

$result=mysqli_query($mysqli,"SELECT tableselect FROM reserve WHERE reserveDate = '". $date ."' AND reserveTime = '". $time ."'");

if($row = $result->fetch_array(MYSQLI_ASSOC)){
    echo $row['tableselect'];
    if($t){
        $disabledAttr = ' disabled="disabled"';
    } else {
        $disabledAttr = '';
    }
}

echo '<input type="radio"' . $disabledAttr . ' />';

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.