0

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
} 
?>
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by facarroll
0
$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>
1

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.