Jump to content

Gerenate tabel in Php


constantin

Recommended Posts

I whant to generate a tabel takeing data from database like this one so the results to be display on 2 columns

 

 

<table width="50%" border="0" cellspacing="0" cellpadding="0" align="center">

<tr>

<td>Picture 1</td>

<td>Details 1</td>

<td width="30"> </td>

<td>Picture 2</td>

<td>Detalii 2</td>

</tr>

<tr>

<td>Picture 3</td>

<td>Details 3</td>

<td> </td>

<td>Picture 4</td>

<td>Details 4</td>

</tr>

<tr>

<td>Picture 5</td>

<td>Details 5</td>

<td> </td>

<td>Picture 6</td>

<td>Details 6</td>

</tr>

<tr>

<td>Picture 7</td>

<td>Details 7</td>

<td> </td>

<td>Picture 8</td>

<td>Details 8</td>

</tr>

</table>

 

Thank you

 

 

Link to comment
https://forums.phpfreaks.com/topic/187909-gerenate-tabel-in-php/
Share on other sites

<?php
// echo table header
echo "<table>\n<tr><td>Picture</td><td>Details</td><td> </td><td>Picture</td><td>Details</td></tr>\n";
$count = 0;
while ($row = mysql_fetch_array($result)){
if ($count == 0) echo "<tr>\n";
$count++;
// echo your data
echo "<td>$row[picture]</td><td>$row[details]</td>\n";
if ($count < 2) echo "<td> </td>\n";
else {
	echo "</tr>\n";
	$count = 0;
}
}
if ($count) {
for ($i = 0; $i < 2; $i++) echo "<td> </td>";
echo  "</tr>\n";
}
echo "</table>\n";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.