php identify 1st recrod from the row

Hello if someone can help me, i need help on this:

[php]

$number = 0;
while($linha_actividades_lista=mysql_fetch_object($resultados_actividades_lista)){
$number++;
if($number==‘1’ || $number % 4 == 0){$risco="‘bg_border_green_left’ style=‘width:240px; float:left; padding-top:10px; padding-bottom:10px;’";
}
else
{
$risco="‘bg_border_green_right’ style=‘width:240px; float:left; padding:10px 0 10px 15px;’";
}
if ($number % 3 == 0){$ultimo =“s”;}else{$ultimo=“n”;}

[/php]

Im trying to identify always the 1st record from the row where i have 3 records. in the example above i was identifying the 1st and multiples of 4, but thats not what i need, i was only doing some experiments.
But what i need is something like this, based on this code i have:

$number=1, $number=2, $number=3, $number=4, $number=5, $number=6, $number=7

I need to apply different properties in the css for the first record in the row, and a different style for the others. This code i built might work , but im not getting the way to identify the first elements.

I Appreciate your help…

Thanks a lot

not to sure what your trying but it will never work that way

to do this you nead to use a for loop
[php]
echo “

”;
for($number = 1; $number <= 3; $number++){
if($number=1){ echo “<td style=“your css for row1”>”; }
if($number=2){ echo “<td style=“your css for row2”>”; }
if($number=3){ echo “<td style=“your css for row3”>”; }
}
echo “
”;
[/php]

not sure how long you want it to count but i put it to 3

You want

$number=1, $number=2, $number=3, $number=4, $number=5, $number=6, $number=7

But with your code, the results are :
$number=1, $number=2, $number=3, $number=4, $number=5, $number=6, $number=7,
$number=8, $number=9, $number=10, $number=11, $number=12

You begin with 1, but it’s to easy begin on 0 and have a new variable $numberToShow with real value.

Try with this code :

[php]
$number = 0;
while($linha_actividades_lista=mysql_fetch_object($resultados_actividades_lista)){
if(($number) % 3 == 0){
$risco="‘bg_border_green_left’ style=‘width:240px; float:left; padding-top:10px; padding-bottom:10px;’";
}else{
$risco="‘bg_border_green_right’ style=‘width:240px; float:left; padding:10px 0 10px 15px;’";
}
if (($number-1) % 3 == 0){
$ultimo =“s”;
}else{$ultimo=“n”;}

       $numberToShow = $number+1;
       $number++;

[/php]

Hello kikesv. Thanks for your help. I made a few changes on this:

[php]if (($number-1) % 3 == 0){[/php]

because it was for display a clear left style in the html. I used the same condition above and put the clear left in the begining of the html in the while. Its working fine now.

Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service