Bonjour,
J'avais compris ce que tu ecris, mais la je suis plus dans ce genre de truc:
J'ai plusieurs problemes dans mon code:
l'affectation du résultat de mon qry dans un tableau:
1 2 3 4
| while ($d = $qry->fetch())
{
$actitable[][$j] = $d[$columns[$j]];
} |
et l'affichage du tableau:
echo "<td>$actitable[$z][$columns[$j]]</td>";
Voici ce que j'ai ecri ce jour.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <?php
$user='utilisateur';
$pass='pass';
$dsn='pgsql:host=localhost;dbname=nomdb';
// nomdb
global $db;
$db = new PDO($dsn, $user, $pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
?>
<html>
<head>
<meta http-equiv="refresh" content="url=index.php">
<meta charset="utf-8">
</head>
<body>
<?php
$actitable = array();
$qry = $db->prepare("SELECT DISTINCT ON (col1) * FROM table WHERE LENGTH(col1) < 13 AND type = 'ACT' ");
$qry->execute();
# Calcule le nombre de colonne dans la requette SQL et stocke les entetes dans le tableau columns
for ($i = 0; $i < $qry->columnCount(); $i++) {
$col = $qry->getColumnMeta($i);
$columns[] = $col['name'];
$numcolums = $i;
}
$numlignes = $qry->rowCount();
echo "<table>";
echo "<tr>";
echo "<th>ligne $z = </th>";
for ($j = 0; $j <= $numcolums; $j++)
{
echo "<th>$columns[$j]</th>";
}
while ($d = $qry->fetch())
{
$actitable[][$j] = $d[$columns[$j]];
}
echo "</tr>";
for ($z = 0; $z <= $numlignes; $z++)
{
echo "<tr>";
echo "<td>ligne $z = </td>";
for ($j = 0; $j <= $numcolums; $j++)
{
echo "<td>$actitable[$z][$columns[$j]]</td>";
}
echo "</tr>";
}
echo "</table>";
echo "il y a $numlignes ligne(s)";
echo "il y a $z ligne(s) retourné(s)";
#print_r($columns);
$qry->closeCursor();
?> |
cordialement,
Vandman
Partager