Jump to content

Set several input radio-buttons as standard


theWheeler

Recommended Posts

Hi! Basicly, this is what I´m trying to do:

 

I have a form with several languages which is categories. Each category has several options and each option is what how many menu-items the user have created for the language. Each language can have several items, and others can have just one... I want to set a standard for each language among these several options to set as primary to use.

 

Each option is an <input type="radio" -box and has a unique id. Because of there are several items in each category I have given each input a category-name, like: name="standard_sv[]" (for swedish) and name="standard_en[]" (for english). I collect all my id´s that I have selected from the form when submitted the form and put the id´s into an array. But when I trying to loop for each value (id) with foreach and trying to store it in the database (mysql), it doesn´t store anything. I have bean sitting here for more then 2 days and can´t solve the problem or see what´s wrong with it... I have my id´s in the array and so on...  and the function sees the array... So I don´t know wy??? Please help...

 

Here some code:

<?php
function Set_Menu_Standard() {

global $standard;

    $sql = "UPDATE nq_menu SET nq_menu.static='0'";
    
    mysql_query($sql) or die (mysql_error($sql));
    
    foreach($standard as $strd) {
    
    $sql = "UPDATE nq_menu SET nq_menu.static='1' WHERE nq_menu.id='$strd'";
    
    mysql_query($sql) or die (mysql_error($sql));
    
    }
}


if(isset($_POST['usemenu'])) {

    $lang = List_Lang();
    
    foreach($lang as $ln) {
    
        $standard[] = $_POST['standard_'.$ln['lang']];
        print_r($_POST['standard_'.$ln['lang']]);
        
    }
    Set_Menu_Standard();
}
?>

<form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post">

<?...?>
<?php
$listmenu = List_Option_Menu();
    foreach($listmenu as $menu) {
    
        if($selectedlang != $menu['lang']) {
            
            $selectedlang = $menu['lang'];
            echo $menu['language'] .':<br>';
        }

        if ($menu['static'] == true) {
            $radiochecked = ' checked';
        } else {
            $radiochecked = '';}
        
        echo $menu['id'].' <input type="checkbox" name="selectbox[]" value="'.$menu['id'] .'">'."\r";
        echo '<input type="radio" name="standard_'.$menu['lang'].'[]" value="'.$menu['id'] .'" title="Use this option"' .$radiochecked .'><a href="#">'.$menu['title'].'</a><br>'."\r";
        
}
?>
<input type="submit" name="usemenu" value="Spara">
</form>

Link to comment
Share on other sites

it's like searching for black holes, you can only tell by knowing what's missing!

Apparently something is missing I just don´t know what... Is it the array $standard or the foreach-loop...? The table in the database doesn´t update the cell with the new value... I know that the connection is working because I can insert or update other values in the same table and others... This is very strange.

 

The $standard in the function contains:

Array
(
    [0] => Array
        (
            [0] => 1
        )

    [1] => Array
        (
            [0] => 2
        )

    [2] => Array
        (
            [0] => 4
        )

)

Link to comment
Share on other sites

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.