[Pugged] Switch Troubles

Chris Van Cleve ciapug@ciapug.org
Tue, 25 Mar 2003 19:55:25 -0600


You win. The ';' was the problem. Interesting how I've never used a for 
loop without one before and using the { } approach causes the a result 
set of less than 6 to duplicate it's last record and a result set 
greater than 6 causes the 6th and 7th rows to be the same background 
color. I'm very confused, but working it out. Thank you for the tip! :)

Chris VC

On Monday, March 24, 2003, at 04:08  PM, Cesar Mendoza wrote:

> Hi,
>
> I think that your problem is in the "for" loop line, remove the 
> semicolon
> (";") at the end of the line. That for loop is doing nothing except 
> setting
> $i to the value of $max. That would explain why the value of $last2 
> never
> changes.
>
> Another way to code it would be:
>  <?php for ($i =0 ;!$result3->EOF; $i++) {
>           $bgcolor = $i & 1 ? "#e1e1e1" : "#f5f5f5";
>  		  <tr bgcolor="<?= $bgcolor ?>">
>  		  <td><?= $result3->fields['team_name'] ?></td>
>  		  <td><?= $result3->fields['team_position'] ?></td>
>  		  <td><?= $result3->fields['team_phone'] ?></td>
>  		  <td><?= $result3->fields['team_email'] ?></td>
>  		  </tr>
>        <?php $result3->MoveNext();
> 	  } ?>
>
>
> "$i & 1" is 0 for even numbers and 1 for odd numbers. In base 2, an odd
> number always end with 1.
>
> Bye
> Cesar Mendoza
> http://www.kitiara.org
> --
> "Hell, n. - The state of being the richest man in
> the world and knowing something exists that you can't buy.
> Have a kleenex, Bill."
>   --Black Parrot (Referring to Bill Gates and Linux)
>
> On Mon, Mar 24, 2003 at 02:02:11PM -0500, Chris Van Cleve wrote:
>> I wrote the following code to change the background color of every
>> other line in a table. For some reason, only the default color is ever
>> assigned. Any ideas?
>>
>> <?php while (!$result3->EOF) {
>>    		for ($i=0; $i < $max; $i++); <-- problem here
>> 			$last2 = $str{strlen($i)-1};
>> 			switch ($last2) {
>> 			case "1":
>> 			case "3":
>> 			case "5":
>> 			case "7":
>> 			case "9":
>> 			    $bgcolor = "#e1e1e1";
>> 				break;
>> 			default:
>> 			    $bgcolor = "#f5f5f5";
>> 			} ?>
>> 		  <tr bgcolor="<?= $bgcolor ?>">
>> 		  <td><?= $result3->fields['team_name'] ?></td>
>> 		  <td><?= $result3->fields['team_position'] ?></td>
>> 		  <td><?= $result3->fields['team_phone'] ?></td>
>> 		  <td><?= $result3->fields['team_email'] ?></td>
>> 		  </tr>
>>       <?php $result3->MoveNext();
>> 	  } ?>
>>
>> -- 
>> Chris 'Vanish' Van Cleve
>> CEO, President, Founder
>> DreamScape Visionery
>> _______________________________________________
>> Ciapug mailing list
>> Ciapug@ciapug.org
>> http://cialug.org/mailman/listinfo/ciapug
>
> _______________________________________________
> Ciapug mailing list
> Ciapug@ciapug.org
> http://cialug.org/mailman/listinfo/ciapug
>
>