Jump to content

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. 
 
 
 
Edited by DrTrans

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.