I am trying to limit rows and columns in a table through while statement, Now when I use :
<?php
$pl_id = $row[‘place’];
$result1 = mysql_query (“SELECT * FROM places”) or die (mysql_error());
$tdcount = 1;
$numtd = 5; // number of cells per row
echo “<table border=1>”;
while ($row1 = mysql_fetch_array ($result1))
{ if ($tdcount == 1)
echo “<tr>”;
echo “<td><a href=hHome_display.php?x=”.$row1[‘id’] .">".$row1[‘place_name’]."</a></td>"; // display as you like
if ($tdcount == $numtd)
{
echo “</tr>”;
$tdcount = 1;
} else {
$tdcount++;
}
} // time to close up our table
if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo “<td> </td>”;
$tdcount++; } echo “</tr>”;
}
echo “</table>”;
?>
It works fine, but if try to bring it into another while statement like :
<?php
$result = mysql_query(“SELECT distinct place FROM hh_details”) or die (mysql_error());
while ($row = mysql_fetch_array ($result))
{
$pl_id = $row[‘place’];
$result1 = mysql_query (“SELECT * FROM places WHERE id = ‘$pl_id’”) or die (mysql_error());
$tdcount = 1;
$numtd = 5; // number of cells per row
echo “<table border=1>”;
while ($row1 = mysql_fetch_array ($result1))
{ if ($tdcount == 1)
echo “<tr>”;
echo “<td><a href=hHome_display.php?x=”.$row1[‘id’] .">".$row1[‘place_name’]."</a></td>"; // display as you like
if ($tdcount == $numtd)
{
echo “</tr>”;
$tdcount = 1;
} else {
$tdcount++;
}
} // time to close up our table
if ($tdcount!= 1)
{
while ($tdcount <= $numtd) {
echo “<td> </td>”;
$tdcount++; } echo “</tr>”;
}
echo “</table>”;
}
?>
It returns a tr with five td’s, the first td displays data, while the others are blank and then another tr, the first td displays data and the others blank. Where am I going wrong? Please help!