Partage
  • Partager sur Facebook
  • Partager sur Twitter

Problème d'affichage fonction scalaire RPAD

Sujet résolu
    3 mars 2021 à 20:50:00

    <?php
    
    require_once ('bdd_connect.php');
    
    $response = $bdd->query('SELECT id, numerocompte, libelle_plan, RPAD(numerocompte, 10, 0) FROM plancomptable');
    $plancomptable = $response->fetchAll();
    $response->closeCursor();
    
    
    ?>
    
    <!DOCTYPE html>
    <html lang="fr">
    
    <head>
        <meta charset="utf-8">
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="../css/bootstrap.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/carousel.css">
        <title>Comptabilité - Plan comptable</title>
        <script src="../js/jquery.js"></script>
        <script src="../js/bootstrap.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script src="../js/script.js"></script>
    </head>
    <body>
         <div id="plancomptable">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h1 style="font-size:25px;text-align:center;color:black;">Liste des comptes</h1>
                        <table>
                            <thead>
                                <tr>
                                    <th>Numéro du compte</th>
                                    <th>Libellé du compte</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    foreach ($plancomptable as $key) {
                                        echo '<tr><td>'.htmlspecialchars($key['numerocompte']).'</td><td>'.htmlspecialchars($key['libelle_plan']).'</td></tr>';
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        
    </body>
    
    
    
    </html>
    

     Bonsoir,

    Je n'arrive pas à afficher le résultat de ma requête. Je souhaite afficher le numéro de compte d'une longueur totale de 10 caractères, mais rien ne se passe.

    Merci d'avance

    • Partager sur Facebook
    • Partager sur Twitter
      3 mars 2021 à 23:01:05

      Ce serait plus facile en aliasant le résultat du RPAD

      Sinon tu fais un (mb_)substr en PHP.

      -
      Edité par julp 4 mars 2021 à 13:33:34

      • Partager sur Facebook
      • Partager sur Twitter
        4 mars 2021 à 13:32:52

        Voici la solution qui fonctionne

        <?php
        
        require_once ('bdd_connect.php');
        
        $response = $bdd->query('SELECT id, numerocompte, libelle_plan, RPAD(numerocompte, 10, 0) AS numerocompte FROM plancomptable');
        $plancomptable = $response->fetchAll();
        $response->closeCursor();
        
        
        ?>
        
        <!DOCTYPE html>
        <html lang="fr">
        
        <head>
            <meta charset="utf-8">
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" href="../css/bootstrap.css">
            <link rel="stylesheet" href="../css/style.css">
            <link rel="stylesheet" href="../css/carousel.css">
            <title>Comptabilité - Plan comptable</title>
            <script src="../js/jquery.js"></script>
            <script src="../js/bootstrap.min.js"></script>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
            <script src="../js/script.js"></script>
        </head>
        <body>
             <div id="plancomptable">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12">
                            <h1 style="font-size:25px;text-align:center;color:black;">Liste des comptes</h1>
                            <table>
                                <thead>
                                    <tr>
                                        <th>Numéro du compte</th>
                                        <th>Libellé du compte</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        foreach ($plancomptable as $key) {
                                            $numerocompte = htmlspecialchars($key['numerocompte']);
                                            echo '<tr><td>'.$numerocompte.'</td><td>'.htmlspecialchars($key['libelle_plan']).'</td></tr>';
                                        }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
        </body>
        
        
        
        </html>
        



        • Partager sur Facebook
        • Partager sur Twitter

        Problème d'affichage fonction scalaire RPAD

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown