I have the following code which displays something like this;

William Science Monday
William Math Tuesday
William English Thursday

but I want it to display without repeating the name William in the lines after the first line.

<?php
$query = mysql_query("SELECT userId, quizTitle, addDate FROM quiz WHERE managerId='".$userid."' AND egroup = '$egroup5' AND passState = 1 ORDER BY userId");

while ($row = mysql_fetch_array($query)){

	$userId = $row['userId'];
	$quizTitle = $row['quizTitle'];
	$addDate = $row['addDate'];
?>
                  <table>
                    <tr>
                      <td><?php echo $userId;?></td>
                      <td><?php echo $quizTitle;?></td>  
                      <td><?php echo $addDate;?></td>
                    </tr>
<?php
} 
?>
$query = mysql_query("SELECT userId, quizTitle, addDate FROM quiz WHERE managerId='".$userid."' AND egroup = '$egroup5' AND passState = 1 ORDER BY userId");
 
$name = '';
while ($row = mysql_fetch_array($query)) {
  $userId = $row['userId'];
  $quizTitle = $row['quizTitle'];
  $addDate = $row['addDate'];
?>
  <table>
    <tr>
      <td><?php 
        if ($userId <> $name) {
          echo $userId;
          $name = $userId;
        }
        else
          echo '&nbsp;';
      ?></td>
      <td><?php echo $quizTitle; ?></td>  
      <td><?php echo $addDate; ?></td>
    </tr>

I've been puzzling on this for months now. Thank You, and what's more, I actually understood it straight off.

$query = mysql_query("SELECT userId, quizTitle, addDate FROM quiz WHERE managerId='".$userid."' AND egroup = '$egroup5' AND passState = 1 ORDER BY userId");
 
$name = '';
while ($row = mysql_fetch_array($query)) {
  $userId = $row['userId'];
  $quizTitle = $row['quizTitle'];
  $addDate = $row['addDate'];
?>
  <table>
    <tr>
      <td><?php 
        if ($userId <> $name) {
          echo $userId;
          $name = $userId;
        }
        else
          echo '&nbsp;';
      ?></td>
      <td><?php echo $quizTitle; ?></td>  
      <td><?php echo $addDate; ?></td>
    </tr>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.