Old 28-06-2010, 13:25   #1 (permalink)
HullBorn
Senior Member
 
HullBorn's Avatar
 
Join Date: Aug 2009
Posts: 140
numbers in while loop

Hi, I have a list of logos, 6 across and 3 down. What I want to do is add a style with no margin on the 1st, 7th and 13th item. I've achieved this using the code below. In case more logos are added I want to be able to achieve it without stating the rownum, e.g.
PHP Code:
if($rownum == or $rownum == or $rownum == 13){
            
$cliList .= $cssMargin;    
        } 

PHP Code:
$cliList "";
    
$rownum 0;
    while(
$rowClient mysql_fetch_array($sqlClients)){
        
$rownum ++;
        
$cliLogo $rowClient['art_image1'];
        
$cliAlt $rowClient['art_title'];
        
$cssMargin " style='margin:0'";
        
        
$cliList .= "<li";
        if(
$rownum == or $rownum == or $rownum == 13){
            
$cliList .= $cssMargin;    
        }    
        
$cliList .= "><img src='/images/uploaded/$cliLogo' alt='$cliAlt'/></li>";
    } 

Would someone be able to help?

Thanks in advance

Wayne
  Reply With Quote
Old 28-06-2010, 13:37   #2 (permalink)
dh
aka Mr Hound
 
dh's Avatar
 
Join Date: Dec 2006
Location: Brackendale
Posts: 4,530
PHP fmod() function

This is what you need.

Divide by six, if remainder = 1.
  Reply With Quote
Old 28-06-2010, 13:39   #3 (permalink)
dh
aka Mr Hound
 
dh's Avatar
 
Join Date: Dec 2006
Location: Brackendale
Posts: 4,530
if(fmod($rownum,6)== 1){ .... }
  Reply With Quote
Old 28-06-2010, 13:50   #4 (permalink)
HullBorn
Senior Member
 
HullBorn's Avatar
 
Join Date: Aug 2009
Posts: 140
cheers dh, that works a treat.
  Reply With Quote
Old 28-06-2010, 14:24   #5 (permalink)
delatorre
Vegetating
 
delatorre's Avatar
 
Join Date: Oct 2008
Location: Pais del Scorchio
Posts: 172
You could also write it without the function call
if ($rownum % 6 === 1) {...}
  Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive
vBulletin © 2000-2009 Jelsoft Enterprises Limited.
Search Engine Optimization by vBSEO 3.0.0 RC8