MySQL
  Home arrow MySQL arrow Page 5 - Displaying Multiple Records Per Row in a MySQL Query Result Set
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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.



     
     
    >>> More MySQL Articles          >>> More By Peter Cole
     

       

    MYSQL ARTICLES

    - MySQL Security Tips
    - Designing a MySQL Database: Tips and Techniq...
    - The Three Most Important MySQL Queries
    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - 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...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT