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... Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/ 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 Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460917 Share on other sites More sharing options...
NebuJohn Posted December 2, 2013 Author Share Posted December 2, 2013 PravinS, Can you explain how to? Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460918 Share on other sites More sharing options...
DrTrans Posted December 2, 2013 Share Posted December 2, 2013 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. Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460924 Share on other sites More sharing options...
Yohanne Posted December 2, 2013 Share Posted December 2, 2013 @Nibujohn: may i saw your solution? Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460927 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";} ?>> Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460928 Share on other sites More sharing options...
Yohanne Posted December 2, 2013 Share Posted December 2, 2013 it is working or not? and i guest if statement is enought to work you asking. Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460931 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 Link to comment https://forums.phpfreaks.com/topic/284436-do-not-display-radio-button-if-its-value-is-in-database/#findComment-1460937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.