MySQL
  Home arrow MySQL arrow Page 3 - 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 
Moblin 
JMSL Numerical Library 
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


    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

    - 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...
    - 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...





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