Jump to content

Do not display Radio Button if its value is in DataBase


NebuJohn

Recommended Posts

Hi,

I have a set of radio buttons with some integer as its value. I use them to make seat selections in an application. If a Radio button is once selected its value will be entered to the DataBase.

My question, can I mask or make invisible, the radio button whose value is found in database? isa that possible?

 

Any help will be appreciable. Thanks in advance.. :)

 

Regards...

only way you can disable a checkbox is to either ..  us js.. ( $('#id-of-form-item').disabled();      or 

 

in php

 

you can 

 
 
if ($value == "$DB_VALUE") { 
 
$disabled = " disabled"; 
 
} else { 
 
$disabled = ""; 
} 
 
 
html: 
 
<input type="radio"  value="" name="" <?php echo $disabled; ?>"  />  // Edited for Radio button, Re-read post. Originally had it as checkbox. 
 
 
 

Thanks for the reply DrTrans..

@JaysonDotPh

 

Here goes my solution

<input type="radio" name="stall" value="41" <?php require ("database.php"); $set = 0; $result = mysqli_query($con,"SELECT * FROM tab1"); $row = mysqli_fetch_array($result); $data = $row['sadlle']; $data = unserialize($data); $max = sizeof($data); for($i=0; $i<$max; $i++){ if($data[$i]==41) { $set = 1;} } if($set==1) { echo "disabled";} ?>>

You shouldn't be querying the database for every radio button. Just one query is required

<?php
require ("database.php"); 
$result = mysqli_query($con,"SELECT * FROM tab1"); 
$row = mysqli_fetch_array($result); 
$data = $row['sadlle']; 
$data = unserialize($data); 

for ($i=1; $i <= 50; $i++) {
    if (in_array($i, $data)) {
        echo "<input type=\"radio\" name=\"stall\" value=\"41\" 'disabled' />
        <span style='color:#ccc'> $i</span><br>";
    } else {
        echo "<input type=\"radio\" name=\"stall\" value=\"41\" /> $i<br>";
    }
}
?>

At the moment, when a number is selected you have to

  • get the serialized array,
  • unserialize,
  • add number to array,
  • reserialize,
  • update database

If you normalized your data and held each selected number is a separate row in the table then you would just need to add a new record when a number was selected

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.