[RESOLU] afficher d'un array sur la table avec (html + php)

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] afficher d'un array sur la table avec (html + php)

Re: afficher d'un array sur la table avec (html + php)

par Henrigo » 10 mars 2021, 19:07

Salut Ryle,
tu es vraiment le meilleur.
Merci Beaucoup

Re: afficher d'un array sur la table avec (html + php)

par Ryle » 10 mars 2021, 18:12

Salutations !

Ta variable $array est un tableau indexé contenant une seule valeur associée à la clé "return". Cette valeur est une chaine json.
Si tu veux pouvoir exploiter la chaine json en php, il te faut d'abord la convertir :
$resultats = json_decode($array['return']);
print_r($resultats);
Tu verras que $resultats contiendra un tableau associatif qu'il sera bien plus simple de parcourir pour construire ton affichage ;)

Re: afficher d'un array sur la table avec (html + php)

par Henrigo » 10 mars 2021, 13:26

Malheureusement je ne peux plus effectuer de modification a mon post je voulais juste dire que j'ai essayé ceci malheureusement ca pas marché
<html>
  <head>
  </head>
  <body>
      <table style="width:100%">
         <caption>Resultats</caption>
         <?php foreach ($array as $item) : ?>
            <tr>
                <th><?php echo $item->ID; ?></th>
                <th><?php echo $item->Name; ?></th>
                <th><?php echo $item->Credit; ?></th>
                <th><?php echo $item->Tor; ?></th>
                <th><?php echo $item->Mandat; ?></th>
                <th><?php echo $item->Date; ?></th>
            </tr>
           <?php endforeach; ?>
       </table>
    </body>
</html>

afficher d'un array sur la table avec (html + php)

par Henrigo » 09 mars 2021, 23:40

Salut a tous,
j'ai besoin d'un coup de main de votre part, j'aimerais afficher le resultat d'un array dans une Table.
l'array en question lorsque je l'affiche voila a quoi cela ressemble.


print_r($array);

Array
(
    [return] => [{"Date":"2021-01-07","Mandat":true,"Tor":false,"Credit":false,"ID":2,"Name":"Serge"},{"Date":"2021-01-13","Mandat":false,"Tor":false,"Credit":true,"ID":3,"Name":"Raoul"},{"Date":"2021-01-13","Mandat":false,"Tor":false,"Credit":true,"ID":4,"Name":"Roger"},{"Date":"2021-01-19","Mandat":false,"Tor":false,"Credit":true,"ID":5,"Name":"Henri"},{"Date":"2021-02-02","Mandat":true,"Tor":true,"Credit":true,"ID":6,"Name":"Bertolt"},{"Date":"2021-02-03","Mandat":false,"Tor":false,"Credit":false,"ID":14,"Name":"Moise"},{"Date":"2021-02-03","Mandat":false,"Tor":false,"Credit":true,"ID":15,"Name":"Rene"},{"Date":"2021-02-04","Mandat":false,"Tor":false,"Credit":true,"ID":29,"Name":"solange"},{"Date":"2021-02-04","Mandat":false,"Tor":true,"Credit":false,"ID":30,"Name":"Martin"},{"Date":"2021-02-28","Mandat":false,"Tor":false,"Credit":false,"ID":35,"Name":"Rose"},{"Date":"2021-03-01","Mandat":false,"Tor":false,"Credit":false,"ID":36,"Name":"Gerald"}]
)


Le tableau devrais ressembler a ceci

<head>
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
th, td {
  padding: 5px;
  text-align: left;
}
</style>
</head>
<body>

<table style="width:100%">
  <caption>Resultats</caption>
  <tr>
     <th>ID</th>
    <th>Name</th>
    <th>Credit</th>
    <th>Tor</th>
    <th>Mandat</th>
    <th>Date</th>
  </tr>
  <tr>
    <td>2</td>
    <td>Serge</td>
    <td>false</td>
    <td>false</td>
    <td>true</td>
    <td>2021-01-07</td>
  </tr>
<tr>
    <td>3</td>
    <td>Raoul</td>
    <td>true</td>
    <td>false</td>
    <td>false</td>
    <td>2021-01-13</td>
  </tr>
</table>

</body>
</html>

Le tableau ressemble a ceci une fois executé


https://ibb.co/gv3h2Mv


Merci bien de votre aide