Jump to content

Recommended Posts

I'm trying to add function to my crud table, whenever I press on the button the table will update with no need to refresh the page with order by name in descending order. Its doesn't do anything and I'm kind of lost I don't think my SQL code is incorrect so it must be somting else that I'm doing

This is my main page where the button and the table is presented

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">  
    <title>Logistics Page</title>
</head>
<body>
    <div class="w3-top">
        <div class="w3-bar w3-white w3-wide w3-padding w3-card">
          <div class="w3-right w3-hide-small">
            <a href="homePage.html" class="w3-bar-item w3-button">homePage</a>
              <a href="playertable.php" class="w3-bar-item w3-button">Players</a>
              <a href="Calandar.php" class="w3-bar-item w3-button">Calendar</a>
              <a href="Logistics.html" class="w3-bar-item w3-button">Logistics</a>
            <a href="Finance.php" class="w3-bar-item w3-button">contracts</a>  
            <a href="about.html" class="w3-bar-item w3-button">About</a>
            <a href="contact.html" class="w3-bar-item w3-button">Contact</a>
            <a href="logout.php" class="w3-bar-item w3-button">Logout</a>
          </div>
        </div>
      </div>
      <div class="container mt-5">
      <?php
        session_start();
        require 'config.php';
        ?>
        <br>
        <br>
         <div class="container mt-4">

<?php include('message.php'); ?>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header">
                <h4>order Details
                    <a href="create-player.php" class="btn btn-primary float-end">Add order</a>
                </h4>
            </div>
            <div class="card-body">

                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                        <th>Photo</th>
                        <th>ID</th>
                        <form action="playercode.php" method="POST" class="d-inline">
                        <!-- <th><input type="submit" value="First Name"  name = "orderbyname" id="orderbyname"></th> -->
                        <th> <button type="submit" name="orderbyname" class="btn btn-dark btn-sm">First Name</button> </th>
                        </form>
                        <th>Last Name</th>
                        <th><input type="submit" value="Date of birth"  name = "ageorder" id="ageorder"></th>
                        <th>E-mail</th>
                        <th>Phone</th>
                        <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $query = "SELECT * FROM players";
                            $query_run = mysqli_query($conn,$query);

                            if(mysqli_num_rows($query_run) > 0)
                            {
                                foreach($query_run as $row)
                                {
                                    ?>
                                    <tr>
                                        <td><img src="<?= $row['Photo']; ?>"width='64px'></td>
                                        <td><?= $row['ID']; ?></td>
                                        <td><?= $row['Fname']; ?></td>
                                        <td><?= $row['Lname']; ?></td>
                                        <td><?= $row['Age']; ?></td>
                                        <td><?= $row['Email']; ?></td>
                                        <td><?= $row['Phone']; ?></td>
                                        <td>
                                            <a href="player-view.php?id=<?= $row['ID']; ?>" class="btn btn-info btn-sm">View</a>
                                            <a href="player-edit.php?id=<?= $row['ID']; ?>" class="btn btn-success btn-sm">Edit</a>
                                            <form action="playercode.php" method="POST" class="d-inline">
                                                <button type="submit" name="delete_player" value="<?=$row['ID'];?>" class="btn btn-danger btn-sm">Delete</button>
                                            </form>
                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            else
                            {
                                echo "<h5> No Record Found </h5>";
                            }
                        ?>
                       
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

   
</body>
</html>

And this is the PHP code in a different page

if(isset($_POST['orderbyname'])){
    $readQuery = "SELECT * FROM players ORDER BY Fname DESC";
    $readRess = mysqli_query($conn,$readQuery);
    if($readRess){
        header("Location: stam.php");
        exit(0);
    }
}

 

36 minutes ago, idan said:

no need to refresh the page

there are existing javascript data-table 'widgets' that will let you click on a heading and sort the rows in a html table for you.

if you want to do this yourself, by getting the data from the server-side code, you will need to use ajax. you would have a clickable element in the markup. when clicked it will trigger some javascript code that will make an ajax request to the server-side code, get the data in the order that you want it, build the markup for the tbody part of the table, then replace the existing markup with the new.

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.