hii all..
Am doing a while loop to display data from my table. below is the output am having:
It is in the form of a table where P and T are 2 different columns
P T
001 t001
001 t002
001 t003
I want to do it like this:
P T
001 t001
t002
t003
I want to display the value of P only once in its respective column.Please help..
Any help will be greatly appreciated.. Thx in advance
regards
Delphine
while loop in PHP
Moderator: General Moderators
Re: while loop in PHP
plz paste here your while loop code then i can help you
Re: while loop in PHP
Here's the code for the while loop:
i want to display the projectName only once..
thx..
Code: Select all
while ($sqlRow=mysql_fetch_array($sqlResult))
{
?>
<tr>
<td>
<?php
echo $sqlRow['projectName'];
?>
</td>
<td><?php echo $sqlRow['taskName'] ?></td>thx..
-
kalpesh.mahida
- Forum Commoner
- Posts: 36
- Joined: Wed Oct 06, 2010 7:09 am
Re: while loop in PHP
Hi,
Bellow code snipest is the answer to your question
Hope this will help you.
Kalpesh Mahida
Bellow code snipest is the answer to your question
Code: Select all
$arrProjectInfo = array(
'1'=>array('ProjectName'=>'001','ProjectTask'=>'t1001'),
'2'=>array('ProjectName'=>'001','ProjectTask'=>'t2001'),
'3'=>array('ProjectName'=>'001','ProjectTask'=>'t3001'),
'4'=>array('ProjectName'=>'002','ProjectTask'=>'t1002'),
'5'=>array('ProjectName'=>'002','ProjectTask'=>'t2002'),
'6'=>array('ProjectName'=>'002','ProjectTask'=>'t3002'),
'7'=>array('ProjectName'=>'003','ProjectTask'=>'t1003'),
'8'=>array('ProjectName'=>'003','ProjectTask'=>'t2003'),
'9'=>array('ProjectName'=>'004','ProjectTask'=>'t1004')
);
$currentProjectName='';
$previousProjectName='';
echo '<table>';
foreach ($arrProjectInfo as $key => $value):
$currentProjectName = $value['ProjectName'];
echo '<tr>';
echo '<td>';
if($previousProjectName != $currentProjectName):
echo $value['ProjectName'];
$previousProjectName = $currentProjectName;
endif;
echo '</td>';
echo '<td>';
echo $value['ProjectTask'];
echo '</td>';
echo '</tr>';
if($previousProjectName=='')$previousProjectName=$currentProjectName;
endforeach;
echo '</table>';
Kalpesh Mahida