Jump to content

Trovars

New Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by Trovars

  1. Hi,

    I need to make it so the items on my page are only displayed if the value in their database column is set to 1 (and 0 for no display). And I should be able to change those values with a checkbox toggle on my admin panel.

    Ideally I wouldn't have to click submit either.

    Table:

    <table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
                          <thead>
                            <tr>
                              <th>ID</th>
                              <th>Item name</th>
                              <th>Item group</th>
                              <th>Actions</th>
                              <th>Display</th>
                            </tr>
                          </thead>
                          <tbody>
                            <?php
                            if($result -> num_rows > 0){
                              while($row = $result-> fetch_assoc()){
                                echo "<tr>";
                                echo "<td>" . $row["id"] ."</td>";
                                echo "<td>" . $row["item_name"]. "</td>";
                                echo "<td>" . $row["group_name"] ."</td>";
                                ?>
                                <?php
                                require_once "deleteitem.php";
                                ?>
                                <td>
                                  <a href="edititem.php?edit=<?php echo $row['id']; ?>" name="edit"><i class="material-icons">edit</i></a>
                                  <a href="?delete=<?php echo $row['id']; ?>" name="delete"><i class="material-icons">delete</i></a>
                                </td>
                                <td>
                                <form action="displayitem.php" method="POST">
                                  <div class="togglebutton">
                                    <label>
                                      <input type="checkbox" name="display">
                                      <span class="toggle"></span>
                                    </label> 
                                  </div>
                                  </form>
                                </td>
                                <?php
                                echo "</tr>";
                            }
                              }
                            ?>
                          </tbody>
                        </table>

    https://i.imgur.com/Qyz6s8v.png

    In displayitem.php

    <?php
    if(isset($_POST['display'])){
        echo '<p>'.$_POST['display'].'</p>';
    	// queries etc here
    }
    ?> 

    I'm not getting the value here unless I add a submit button.

    Guessing jQuery / AJAX is the way to go but can't seem to find any good tutorials on it, are there any other suitable approaches to this?

     

     

     

     

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