Page 1 of 1

table header <hd>

Posted: Thu Jul 07, 2011 1:59 am
by nadeem14375
Dear all,

i have the following code to show a table header:

while ($get_row = mysql_fetch_assoc($get))
{
echo '<table border="1" cellpadding="2" cellspacing="2" width="200">
<tr>
<th>'.'Name'.'</th>
<th>'.'Phone No'.'</th>
</tr>
<tr>
<td width="50%">'. $get_row['name'].'</td>
<td width="50%" align="right"> '.$get_row['num'].'</td>
</tr>
</table>';
}

it repeats the heading on every row of the column:

Name Phone No
ahmed 34343433
Name Phone No
gul 3434343432
Name Phone No
shah 99228282
Name Phone No
nawaz 838372777
Name Phone No
waheed 4774474
Name Phone No
Wali 87222727

the heading should be only on first row.

what's the wrong?

Regards:

Re: table header <hd>

Posted: Thu Jul 07, 2011 6:49 am
by oscardog
Here you go...

Code: Select all

$count = 0;
echo '<table border="1" cellpadding="2" cellspacing="2" width="200">';
while ($get_row = mysql_fetch_assoc($get))
{
if($count == 0) {
echo '<tr>
<th>'.'Name'.'</th>
<th>'.'Phone No'.'</th>
</tr>';
}
echo '<tr>
<td width="50%">'. $get_row['name'].'</td>
<td width="50%" align="right"> '.$get_row['num'].'</td>
</tr>';
$count++;
}
echo '</table>';

Re: table header <hd>

Posted: Thu Jul 07, 2011 6:52 am
by social_experiment
Or the code to create the table header can be placed outside the while loop.

Re: table header <hd>

Posted: Thu Jul 07, 2011 7:52 am
by nadeem14375
thanks

it should be out side the while loop.
social_experiment wrote:Or the code to create the table header can be placed outside the while loop.

Re: table header <hd>

Posted: Thu Jul 07, 2011 3:27 pm
by oscardog
social_experiment wrote:Or the code to create the table header can be placed outside the while loop.
...I am having a slow day. Literally cannot believe I moved the table tags outside and not the headers :banghead: