Problèmes de lenteur Datatables - Mysql

Astolpho Messages postés 72 Date d'inscription vendredi 8 avril 2022 Statut Membre Dernière intervention 5 mars 2024 - 1 janv. 2024 à 21:08
Astolpho Messages postés 72 Date d'inscription vendredi 8 avril 2022 Statut Membre Dernière intervention 5 mars 2024 - 2 janv. 2024 à 12:42

Bonjour,

J'ai un problème de lenteur d'affichage avec un tableau qui utilise le framework Datatables.

J'ai une page qui met plus de 12 secondes pour se charger, je ne sais pas ou regarder pur trouver le problème.

Si quelqu'un pouvait m'aiguiller pour que je puisse trouver d'où ça vient.

Merci

2 réponses

jordane45 Messages postés 38150 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 29 avril 2024 4 651
1 janv. 2024 à 21:14

Bonjour

Si tu veux de l'aide, il faut avant tout que tu montres le code qui te pose problème.

Le souci est en rarement le plugin data table mais la structure de ta base de données ou les requêtes que tu fais pour afficher ce que tu souhaites dans ta page.


0
Astolpho Messages postés 72 Date d'inscription vendredi 8 avril 2022 Statut Membre Dernière intervention 5 mars 2024
2 janv. 2024 à 12:42

Bonjour Jordan,

C'est la méthode pour récupérer les informations : 

class/customers.php

public function displayCustomers()
  {


    try {
    } catch (Exception $e) {
      die('Erreur : ' . $e->getMessage());
    }

    //Connection a la bdd
    $db = getDB();

    $stmt = $db->prepare("SELECT 
                                 customers.fullname as fullname, 
                                 customers.id_type_of_customers as id_type_of_customers, 
                                 customers.email as email, 
                                 customers.customer as customer, 
                                 address as address, 
                                 zipcode as zipcode,

                                 type_of_customers.type_of_customer as 
                                 type_of_customer
                                
                                 FROM customers     
                                 LEFT JOIN users ON customers.id = users.id
                                 LEFT JOIN type_of_customers ON customers.id_type_of_customers  = 
                                     type_of_customers.id_type_of_customers

    
                                 WHERE customers.id = :user_id AND mode ='1'");

    $stmt->bindParam(':user_id', $_SESSION['user_id']);
    $stmt->execute();
    return $stmt->fetchAll(PDO::FETCH_ASSOC);
  }

L'appel de la méthode : 

vue/array/displayCustomers.php

$manager = new CustomerManager();

$customerDataList = $manager->displayCustomers();

    <thead>

                <tr>

                    <th>ID</th>

                    <th>Fullname</th>

                    <th>Statut</th>

                    <th>Email</th>

                    <th>Adresse</th>

                    <th>Code postal</th>

                    <th></th>

                </tr>

            </thead>

            <tbody>

                <?php foreach ($customerDataList as $donnees) : ?>

                    <tr>

                        <td width="1%"><a href="<?= URLSITE ?>form/customer.php?customer=<?= $donnees['customer'] ?>"><button type="button" class="btn btn-block btn-secondary btn-xs btn-flat"><i class="nav-icon fas fa-pencil"></i></td></button></a>

                        <td width="20%"><?= $donnees['fullname'] ?></td>

                        <td width="10%"><?= $donnees['type_of_customer'] ?></td>

                        <td width="20%"><?= $donnees['email'] ?></td>

                        <td width="25"><?= $donnees['address'] ?></td>

                        <td width="8%"><?= $donnees['zipcode'] ?></td>

 </tr>

                <?php endforeach; ?>

            </tbody>

        </table>

la page ou j'affiche le tableau :

array/customers.php

<?php include('../inc/head.php'); ?>

<!-- Default box -->

<?php include('../inc/title_start.php'); ?>

<h1>Clients</h1>

<?php include('../inc/title_end.php'); ?>

<?php include('../controleur/array/displayCustomers.php'); ?>



 

<!-- Page specific script -->

<script>

    $(function() {

        $("#customer").DataTable({

            "responsive": true,

            "lengthChange": false,

            "autoWidth": true,

            "buttons": ["excel", "pdf", "print"]

        }).buttons().container().appendTo('#customer_wrapper .col-md-6:eq(0)');

    });

</script>

0