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?

$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)

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 . ' />';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.