-1

I am using codeigniter framework for my website. In views I have a php file which displays a table like this:

            #        Name

checkbox    1   Aanchal 


checkbox    2   Abhijeet 

Now i want to get id of all the selected checkboxes (can be multiple also) such that when the user click on delete button present in navigation bar, the selected entries get deleted.

Here is the code I am using in views:

<header class="jumbotron subhead" id="overview">
    <div class="subnav">
    <ul class="nav nav-pills">
        <li><a href="controller 1">Home</a></li>
        <li><a href="controller 2">Add</a></li>
        <li><a href="controller 3">Edit</a></li>
        <li><a href="controller 4">Delete</a></li>
    </ul>
    </div>
</header>

<div id="content" style="height: 500px; width: 800px">
    <table class="table table-striped">
        <thead>
        <tr>
        <th></th>
        <th>#</th>
        <th>Name</th>
        </tr>
        </thead>
        <tbody>
            <?php
        for($i=0;$i<sizeof($json_string);$i++)
        {       
            $sno = $i + 1;
        ?>
        <tr>
        <td><input type="checkbox" id=<?php $sno?> value=<?php $sno?> /><br />
        </td>
        <td><?php print_r($sno)?></td>
        <td><?php print_r($json_string[$i]->fName);
        if(isset($json_string[$i]->lName))
        {
            print_r($json_string[$i]->lName);
        }
        else
            print_r("");
        ?>
        </td>
    </tbody>
        </table>

Controller 4 will be having code to delete the selected entries from string, so what should I do to get and pass the selected checkboxes' ids to controller 4

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lokis
  • 11
  • 5
  • probable duplicate http://stackoverflow.com/questions/4112863/how-to-get-checkbox-values-using-php-code-ignitor-in-controller – 000 Jul 28 '12 at 15:14

1 Answers1

0

Set checkbox attribute "name", for example will looks like

<input type="checkbox" name="itemIds[]" id=<?php $sno?> value=<?php $sno?> />

Also add form and put table inside this form. Then on delete button click submit form, so in post data you will get checked items values

DTukans
  • 339
  • 2
  • 7
  • will this work even if my delete button is not in form. and can you please paste code snippet for better understanding – Lokis Jul 28 '12 at 09:00
  • you can put button outside form also simple link or div element, and add click event, for example jquery form submit onclick="$('#frmTable').submit();" – DTukans Jul 28 '12 at 09:06
  • Your table content Delete – DTukans Jul 28 '12 at 09:08
  • but how will it post the checked values to a function in controller ?? – Lokis Jul 28 '12 at 13:27
  • Look this topics and answers http://stackoverflow.com/questions/8522070/php-checkbox-multiple-delete, http://stackoverflow.com/questions/8529005/php-multiple-checkbox-delete – DTukans Jul 31 '12 at 12:12