MySQL
  Home arrow MySQL arrow Page 3 - 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 - Digging Deeper
    ( Page 3 of 5 )

    What we are really interested in is the link that displays the images in the gallery in a horizontal format.

    The URL in the code above looks like this:

     http://localhost/gallery/show_pictures_h.php?CAT=3&AID=2&LOC=2

    We start once again with the code needed to connect to the mysql server and request info from the query string attached to the URL. It is important to clean up query strings before you submit a request to the database. One of the simpliest and most effective means to do so is to use the built in PHP 'htmlspecialchars' function which prevents html markup from adding dangerous code to your query. The function has more capabilities then presented here, but in general it does the following.

    •  · & (ampersand) becomes '&
    •  " " (double quote) becomes '"' when ENT_NOQUOTES is not set. 
    •  ' ' (single quote) becomes ''' only when ENT_QUOTES is set. 
    •  < (less than) becomes '&lt;
    •  > (greater than) becomes '&gt;

    <?php
    require("../../includes/db_config.php");  // connect to mysql server from protected directory
    if(isset($_GET['CAT']) && ($_GET['AID'])) {
     $CAT = htmlspecialchars($_GET['CAT']); // clean up query string variable
     $AID = htmlspecialchars($_GET['AID']); // clean up query string variable
     $LOC = htmlspecialchars($_GET['LOC']); // clean up query string variable
     
     // get album name first to populate title bar
     $sql_T = "SELECT albums.albumNAME FROM albums WHERE catID = '$CAT' AND albumID = '$AID' ";
     $sql_T_result = @mysql_query($sql_T, $connection)
      or die ("Could not execute your select albumNAME request");
     $row_T = @mysql_fetch_array($sql_T_result);
     $NAME = stripslashes($row_T['albumNAME']);
     
     // get images from album
    $sql = "
     SELECT
      albums.albumNAME,
      images.imgID,
      images.catID,
      images.albumID,
      images.locID,
      images.imgTITLE,
      images.thumbPATH,
      images.thumbNAME,
      images.copyright
     FROM images, albums
     WHERE images.catID = '$CAT' AND images.albumID = '$AID' AND images.albumID = albums.albumID
     ORDER BY copyright, thumbNAME";

     $result = @mysql_query($sql, $connection);
     if(!$result) {
      print "Could not execute your select images request";
      exit;
      }
      
     $num = @mysql_num_rows($result); 
     // you choose how many columns you want to display in each table row
     $thumbcols = 5;
     // quick and dirty formula to figure out how many rows you will need
     $thumbrows = 1+ round($num / $thumbcols); 
     }
    ? >
       



     
     
    >>> 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 6 Hosted by Hostway
    Stay green...Green IT