tags:

views:

311

answers:

3

Hello I have an array of "Id's" that comes from DB. I have also a table like this :

And the "Id's" array contain record id, ie:

Array ( [0] => Array ( [id] => 1 [code] => GHY87 [description] => Hello World ) )

Now i want, when i checked any-one check box & then click on Edit Button(Link) then i get the id of that check box.

NOTE: I only want to use php code nor jScript neither jQuery.

Please Help..

A: 

Make the edit button a submit button for a form. Each check box is a single element in the form that is submitted. All of them are always submitted.

When a post is received, search through the values posted for on or more that are set to checked.

Jacob

TheJacobTaylor
A: 

<input type=checkbox name=mycheckbox value=1> Hello World

<?php
echo "The ID of my checkbox is {$_GET['mycheckbox']}";
?>

Maybe you should use a <select> box instead.

Havenard
A: 

My simple suggestion:

<?php
if (!empty($_POST))
{
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    exit();
}
    $ids = array( 
      0 => array(
        'id' => 1,
        'code' => 'GHY87',
        'description' => 'Hello World'
       ),
      1 => array(
        'id' => 2,
        'code' => 'OTHER',
        'description' => 'Bye World'
       )
      );
    function checkboxes($ids)
    {
     foreach ($ids as $id)
     {
     ?>
     <input type="checkbox" name="ids[]" value="<?php echo $id['id']; ?>" /> <?php echo $id['description'];?> (<?php echo $id['code'];?>)<br />
     <?php
     }
    }
?>
<form id="myForm" method="post">
    <?php checkboxes($ids); ?>
    <input type="submit" value="Edit" />
    or
    <a href="#" onclick="document.getElementById('myForm').submit(); return false;">Edit</a>
</form>

output:

<form id="myForm" method="post">
    <input type="checkbox" name="ids[]" value="1" /> Hello World (GHY87)<br />
    <input type="checkbox" name="ids[]" value="2" /> Bye World (OTHER)<br />
    <input type="submit" value="Edit" />
    or
    <a href="#" onclick="document.getElementById('myForm').submit(); return false;">Edit</a>
</form>

...if check first checkbox and click Edit, you get:

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

)

...if check boths:

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

)
inakiabt