SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Query Result

  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query Result

    Newbie question:

    I have to query my database for a list of pictures + their respective title. These pictures and descriptions should be listed on my index-page. I currently have a table with 4 columns per row, so 4 results per row. This is something I should get:

    <tr><td>Pic1</td><td>Pic2</td><td>Pic3</td><td>Pic4</td></tr>
    <tr><td>Pic5</td><td>Pic6</td><td>Pic7</td><td>Pic8</td></tr>

    This is probably very easy, but I have no idea how to do this.
    Dillen Media Solutions

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is relatively easy, but where does the title go?

  3. #3
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't implement the title in the question because I would be able to figure that out myself once I found out how the other thing was done. The title can easily be put in the same <td> as the picture, so that would not cause any extra problems
    Dillen Media Solutions

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Here is some pseudo code that might be helpful.

    PHP Code:
    <?php

    // fetch the images from the database

    $query 'SELECT name, title FROM images';
    $result mysql_query($query) or die(mysql_error());

    // display the images

    $counter 0;

    while(( 
    $image mysql_fetch_assoc($result) ) && ( $counter++ >= ))
    {
      
    // the start of a new row?
      
      
    if( $counter == )
        echo 
    '<tr>';
      
      
    // display the current image
      
      
    echo '<td><img src="'$image['name'], '" alt="" title="'$image['title'], '" /></td>';
      
      
    // end of the row?
      
      
    if( $counter == )
        echo 
    '</tr>';
    }

    // fill the empty cells

    if( $counter != )
    {
      do { echo 
    '<td></td>'; }
      while( 
    $counter++ % != );
      
      echo 
    '</tr>';
    }

    ?>
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •