NebuJohn Posted December 2, 2013 Share Posted December 2, 2013 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... Quote Link to comment Share on other sites More sharing options...
PravinS Posted December 2, 2013 Share Posted December 2, 2013 you can disable them, which can be visible but cannot be checked Quote Link to comment Share on other sites More sharing options...
NebuJohn Posted December 2, 2013 Author Share Posted December 2, 2013 PravinS, Can you explain how to? Quote Link to comment Share on other sites More sharing options...
DrTrans Posted December 2, 2013 Share Posted December 2, 2013 (edited) 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. Edited December 2, 2013 by DrTrans Quote Link to comment Share on other sites More sharing options...
Yohanne Posted December 2, 2013 Share Posted December 2, 2013 @Nibujohn: may i saw your solution? Quote Link to comment Share on other sites More sharing options...
NebuJohn Posted December 2, 2013 Author Share Posted December 2, 2013 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";} ?>> Quote Link to comment Share on other sites More sharing options...
Yohanne Posted December 2, 2013 Share Posted December 2, 2013 (edited) it is working or not? and i guest if statement is enought to work you asking. Edited December 2, 2013 by JaysonDotPH Quote Link to comment Share on other sites More sharing options...
Barand Posted December 2, 2013 Share Posted December 2, 2013 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.