# Limiting Columns And Rows In Php-please Help!

**URL:** <https://forum.kirupa.com/t/limiting-columns-and-rows-in-php-please-help/238374>\
**Category:** programming\
**Created:** [September 10, 2007, 6:13pm UTC](https://forum.kirupa.com/t/limiting-columns-and-rows-in-php-please-help/238374 "2007-09-10T18:13:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shdt](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shdt](https://forum.kirupa.com/u/shdt)\
**Post date:** [September 10, 2007, 6:13pm UTC](https://forum.kirupa.com/t/limiting-columns-and-rows-in-php-please-help/238374/1 "2007-09-10T18:13:53Z")

</div>

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\>&nbsp;\</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\>&nbsp;\</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!
