Reply to Re: Need help with my code reading flat file into HTML table

Your name:

Reply:


Posted by JackM on 01/22/06 02:38

Geoff Berrow wrote:
> Message-ID: <bpadnUgDvvR9FU_enZ2dnUVZ_sSdnZ2d@comcast.com> from JackM
> contained the following:
>
>

>>I can follow most of what you did but there are two lines that are
>>foreign to me:
>>
>>$spaces=($lines%$cols>0)? 1 : 0;
>
> The question mark is the ternary operator. It's a shorter way of
> writing if/else. '$lines%$cols' divides $lines by $cols and gives the
> remainder. If there is a remainder the result will be greater than 0 and
> $spaces is set to 1. If there is no remainder it is set to zero.
>
> I could have written
>
> if($lines%$cols>0){
> $spaces= 1;
> }
> else{
> $spaces=0;
> }
>
>
>>$rows=floor($lines/$cols)+$spaces;
>
> If we divide $lines by $cols we get the number of rows. The function
> floor just rounds it down. So if you have 9 lines and 4 columns the
> answer would be two. In fact the answer is two until you have 12 lines.
> However, if it doesn't divide exactly you need another row. That being
> the case, $spaces is already set to one and so we have the correct
> number.

Thanks for the explanations. Caught me off guard because I never came
across the ? or floor in code before. Not only did you solve my problem
but you taught me something new at the same time. Your explanations are
now crystal clear to me. Much obliged.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация