12.7. Performing a SubquerySometimes you'll want to display the data in a linked table as a list instead of repeating all of the values from the joined table. For example, when listing books, it would look nicer to list authors in one cell of your table. Example 12-12 uses a second query and a loop to accomplish this. Example 12-12. Displaying the authors in a list
Define a second query and result set for the authors. For each title, a query of the authors table can retrieve a variable number of authors. Count the result set using the numRows function. To avoid an empty cell, if there were no authors, you display None. Use the $author_count variable again while looping so as not to put a comma after the last author name in the list. The result is this nicer format, shown in Figure 12-14. Figure 12-14. Authors displayed on a single lineIn Chapter 13, we'll talk about storing information in sessions and how to limit access to pages. |