Jump to content
Larry Ullman's Book Forums

Question About Displaying Query Results


Recommended Posts

I have a query which retrieves member's name and books he/she read. The query returns name of the member, book title and book author. I want to print member name only once, and then a table with books names and authors in it.

 

 

 

 

 

if(mysqli_num_rows($r) > 0 )

{

 

//Here somewhere I need to print member name. But query result is not yet found.

echo '<table align="center" cellspacing="5" cellpadding="5" width="75%">

<tr>

 

<td align="left"><b>'. $t1 .'</a></b></td>

<td align="left"><b>' . $a1 .'</a></b></td>

</tr>';

 

while($row = mysqli_fetch_row($r))

{

// Is there anything which can hold $membername = $row[1]...But how to print it above the table?

//How can I print the name only once?

echo '<tr>

 

<td align="left">' . $row[6] . '</td> //book title

<td align="left">' . $row[7] . '</td> //author

}

Link to comment
Share on other sites

What you want to do is create a flag variable. Assign it a false value before the loop. Then, within the loop, see if the value you want to print equals the value of that flag variable. If it doesn't, then it's a new member and you should print it, then assign that value to the flag variable. That will do it.

Link to comment
Share on other sites

 Share

×
×
  • Create New...