Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts

    3 Items per row or less IF truble

    Hi im writing a script wich i would like to display 3 pruducts in a row.

    The code below works if there is 3 items per row. but i still need it to end the div even if theres only 1 or 2

    PHP Code:
    $i 0;
            
    while (
    $row mysql_fetch_array($result))
    {
        
    extract($row);
                                    
        if (
    $i $itemsPerRow == 0) {
            
    $prod .= '<div id="modules">'// Start main class
        
    }
                
        
    $prod .= '<div id="mod'$i .'">' .  // sub class
                
    '<div class="padding">' .
                    
    '<div class="text">' .
                        
    '<b><a href="#" title=""></a></b>' .
                        
    '<p></p>' .
                    
    '</div>' .
                
    '</div>' .
            
    '</div>';
        
    $i += 1;
                    
        if (
    $i $itemsPerRow == 0)
        {
            
    $i 0;
            
    $prod .= '</div>'// Close class full row or not
        
    }

    Last edited by Lee Stevens; 11-18-2007 at 08:57 PM.

  • #2
    Regular Coder
    Join Date
    Nov 2006
    Posts
    247
    Thanks
    13
    Thanked 26 Times in 24 Posts
    PHP Code:
    // get total items (edit as needed)
    $get_total mysql_query("SELECT count(*) AS total FROM table_name");
    $totalf mysql_fetch_array($get_total);
    $total $totalf['total'];

    $i 0;
    $n 1;
            
    while (
    $row mysql_fetch_array($result))
    {
        
    extract($row);
                                    
        if (
    $i $itemsPerRow == 0) {
            
    $prod .= '<div id="modules">'// Start main class
        
    }
                
        
    $prod .= '<div id="mod'$i .'">' .  // sub class
                
    '<div class="padding">' .
                    
    '<div class="text">' .
                        
    '<b><a href="#" title=""></a></b>' .
                        
    '<p></p>' .
                    
    '</div>' .
                
    '</div>' .
            
    '</div>';
        
    $i += 1;
        
        
    // close if is third item in row or last item          
        
    if ($i $itemsPerRow == OR $n == $total)
        {
            
    $i 0;
            
    $prod .= '</div>'// Close class full row or not
        
    }

        
    $n++;

    I THINK that'll solve it. It's how I used to do it, but when I do thing's like this now, I just use floating DIVs. Anyway, hope this works for you though.
    Last edited by Majoracle; 11-18-2007 at 11:35 PM.

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Thank you for your reply, i finaly fixed it a added a for clause

    PHP Code:
    for ($i 0$i $numItem$i++)
    {
    // code inside here fideled a lil bit.

    So funny how something can seem so easy but somtimes take so long


  •  

    Posting Permissions

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