codeigniter - How to increase id by 1 or change it completely in HTML using PHP code -


i getting results database , showing them in datatable using query

  $result['gettablegroup'] = $this->gettablegroup();   return $this->load->view('users/index', $result); 

and here code of view

<table class="table">     <thead>        <tr>           <th>name</th>           <th>group users</th>           <th>status</th>           <th>action</th>        </tr>     </thead>     <tbody>        <?php foreach ($gettablegroup $value) : ?>        <tr>           <td>              <?= $value->group_name ?>           </td>           <td>              <?php if ($value->group_status == 'on'): ?>              <div class="switch">                 <div class="onoffswitch">                    <input type="checkbox" checked class="onoffswitch-checkbox" id="example1" name="group-status">                    <label class="onoffswitch-label" for="example1">                    <span class="onoffswitch-inner"></span>                    <span class="onoffswitch-switch"></span>                    </label>                 </div>              </div>              <?php elseif ($value->group_status == 'off'): ?>              <div class="switch">                 <div class="onoffswitch">                    <input type="checkbox" checked class="onoffswitch-checkbox" id="example2" name="group-status">                    <label class="onoffswitch-label" for="example2">                    <span class="onoffswitch-inner"></span>                    <span class="onoffswitch-switch"></span>                    </label>                 </div>              </div>              <?php endif; ?>           </td>        </tr>        <?php endforeach; ?>     </tbody>  </table>

code working fine problem here im using onoff switch list , id in input , label same code of section not working fine trying generate random numbers or loop increase 1 can put changer in id , label every time each <td> runs id in label change , code work fine

<td>     <?php if ($value->group_status == 'on'): ?>     <div class="switch">        <div class="onoffswitch">           <input type="checkbox" checked class="onoffswitch-checkbox" id="example1" name="group-status">           <label class="onoffswitch-label" for="example1">           <span class="onoffswitch-inner"></span>           <span class="onoffswitch-switch"></span>           </label>        </div>     </div>     <?php elseif ($value->group_status == 'off'): ?>     <div class="switch">        <div class="onoffswitch">           <input type="checkbox" checked class="onoffswitch-checkbox" id="example2" name="group-status">           <label class="onoffswitch-label" for="example2">           <span class="onoffswitch-inner"></span>           <span class="onoffswitch-switch"></span>           </label>        </div>     </div>     <?php endif; ?>  </td>

if want set id dynamic set variable use . use $i first 1 increase id unique.if need else inform. use $i = 1; increment last dynamic

<table class="table">     <thead>     <tr>         <th>name</th>         <th>group users</th>         <th>status</th>         <th>action</th>     </tr>     </thead>     <tbody>     <?php     $i = 1;     foreach ($gettablegroup $value) { ?>          <tr>             <td>                 <?= $value->group_name ?>             </td>             <td>                 <?php if ($value->group_status == 'on'): ?>                     <div class="switch">                         <div class="onoffswitch">                             <input type="checkbox" checked class="onoffswitch-checkbox" id="example<?= $i ?>"                                    name="group-status">                              <label class="onoffswitch-label" for="example<?= $i ?>">                                 <span class="onoffswitch-inner"></span>                                 <span class="onoffswitch-switch"></span>                             </label>                         </div>                     </div>                 <?php elseif ($value->group_status == 'off'): ?>                     <div class="switch">                         <div class="onoffswitch">                             <input type="checkbox" checked class="onoffswitch-checkbox" id="example<?= $i ?>"                                    name="group-status">                              <label class="onoffswitch-label" for="example<?= $i ?>">                                 <span class="onoffswitch-inner"></span>                                 <span class="onoffswitch-switch"></span>                             </label>                         </div>                     </div>                  <?php endif; ?>             </td>          </tr>          <?php         $i++;     } ?>     </tbody> </table> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -