Belle question, le calcul du rowspan se fait en comptant les factures. Voici le code que j'ai créé :
<?php
/**
* @author Truth
* @copyright 2011
*/
$dsn = "mysql:host=localhost;dbname=test";
$dbc = new PDO($dsn, 'root', 'pass');
$query = 'SELECT * FROM invoice';
$stmt = $dbc->prepare($query);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$result[$row['client_id']][] = $row['invoice_id'];
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Metas -->
<meta http-equiv="content-type" content="utf-8" />
<meta name="author" content="Truth" />
<title>Invoice Rowspan Example</title>
</head>
<body>
<table id="invoices" border="1">
<thead>
<th>Client</th>
<th>Invoices</th>
</thead>
<tbody>
<?php
foreach($result as $id => $invoices) {
echo '<tr>';
echo '<td rowspan='. count($invoices) . '>' . $id . '</td>';
$count = 0;
foreach ($invoices as $invoice) {
if ($count != 0) {
echo '<tr>';
}
echo "<td>$invoice</td>";
echo "</tr>";
$count++;
}
}
?>
</tbody>
</table>
</body>
</html>
Cela génère une table selon vos besoins. S'il y a quelque chose que vous ne comprenez pas, commentez et je vous expliquerai