MySQL
  Home arrow MySQL arrow Page 5 - Displaying Multiple Records Per Row in...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Displaying Multiple Records Per Row in a MySQL Query Result Set
By: Peter Cole
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 44
    2004-05-19

    Table of Contents:
  • Displaying Multiple Records Per Row in a MySQL Query Result Set
  • Getting Connected
  • Digging Deeper
  • Getting the Query Results to Display Horizontally
  • The Look we want and the Secret that gets you there

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Displaying Multiple Records Per Row in a MySQL Query Result Set - The Look we want and the Secret that gets you there


    (Page 5 of 5 )

    Between the header and footer in show_pictures_h.php, the php code and html shown above will parse to look like this:

    Records in MySQL

    The trick, discovered only after repeated dead ends is the nested loop. The first for loop finds out how many rows to display and prints the <tr> tags. The second nested loop finds out how many <td> tags to print in each row. And because we already defined this to equal to 5, the inside loop prints out 5 table cells before giving control back over to the outside loop which then prints another row (if need be) and then lets the inside loop do its thing again until both loops are satisfied and no longer return a true value.

    Because the data we want to display resides in the table cells, we don't break out the array values that contain all that data until we are inside the 2nd loop.

    Cha ching! In our case we only wanted the thumbnail image and the caption. Each thumbnail however is surrounded with a hyperlink that requests something along these lines:

    http://localhost/gallery/enlarge_image.php?ID=22&CAT=3&AID=2

    Clicking on the thumbnail image opens another page with a larger version of the image. Nothing special here... just another query that displays the results of the SELECT string parameters (imageID, catalogID and albumID) attached to the thumbnail hyperlink. The code behind the enlarge_image.php page is almost identical to what we have looked at here. The only difference is in the html and the CSS used to display the one large image rather than loop thru an array of returned rows.

    Records in MySQL

    You may see all of this in action at Mooney Mountain Guides Please be aware that all mountaineering images displayed here are © 2004 by Art Mooney.

    Hope this helps you with your PHP/MySQL projects and remember, keep it simple.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    MYSQL ARTICLES

    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database
    - Working with PHP and MySQL
    - Getting PHP to Talk to MySQL
    - Creating an RSS Reader: the Reader
    - MySQL Security Overview
    - Creating the Admin Script for a PHP/MySQL Bl...
    - Creating the Blog Script for a PHP/MySQL Blo...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway