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:
table header <hd>
Moderator: General Moderators
Re: table header <hd>
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>';
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: table header <hd>
Or the code to create the table header can be placed outside the while loop.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
nadeem14375
- Forum Newbie
- Posts: 23
- Joined: Sat Oct 30, 2010 2:11 am
Re: table header <hd>
thanks
it should be out side the while loop.
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>
...I am having a slow day. Literally cannot believe I moved the table tags outside and not the headerssocial_experiment wrote:Or the code to create the table header can be placed outside the while loop.