Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I need to divide and see if there's remainder....

LEGEND ,
Jun 27, 2006 Jun 27, 2006
how can I do that.

specifically, I've got repeating sections that I need to style with a left
or right float. They're working fine, but I now need to insert a statement
that says:

if $i/2 has a remainder, print right
if $i/2 has no remainder, print left

Page is here:
http://demo.mediachurch.com/news.php

I currently have the following code to generate my news listings:

if ($gID == $newsGroup) { //if groupid in array matches newsGroup ID
if ($pid != $newsGroup) { //if past newsGroup ID matches current
newsGroup ID
if ($pid == 777) { //condition set at beginning
echo '<div id="'.$gName.'" class="newsList">';
echo '<h2>'.$gName.$i.'</h2>';//remove $i when done as it just shows
count
}
echo '<h3>'.$newsTitle.'</h3>';
echo $newsContent;
}
if ($pid == $newsGroup) { //if past newsGroup id matches current
newsGroup ID
echo '<h3>'.$newsTitle.'</h3>';
echo $newsContent;
}
$pid = $newsGroup; //set current newsgroup to past
}


Any optimization of code is also welcome. This was a hard oen to figure out
for me and I don't really care for so many nested If statements, but am too
tired rightnow to see a better way.

--

TIA,

Jon Parkhurst
PriivaWeb
http://priiva.net.


TOPICS
Server side applications
289
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2006 Jun 27, 2006
crash wrote:
> if $i/2 has a remainder, print right
> if $i/2 has no remainder, print left

if ($i%2) {
// code to float right
}
else {
// code to float left
}

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2006 Jun 27, 2006
Thanks David! I had just found that on php.net (that "functions" drop down
always gets me) and was just trying to figure out syntax - thank you very
much!!!!

Jon

"David Powers" <david@example.com> wrote in message
news:e7s9f5$sld$1@forums.macromedia.com...
> crash wrote:
>> if $i/2 has a remainder, print right
>> if $i/2 has no remainder, print left
>
> if ($i%2) {
> // code to float right
> }
> else {
> // code to float left
> }
>
> --
> David Powers
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "Foundation PHP 5 for Flash" (friends of ED)
> http://foundationphp.com/


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2006 Jun 27, 2006
works perfectly David, thank you very much!

http://demo.mediachurch.com/news.php

"crash" <crash@bcdcdigital.com> wrote in message
news:e7s9vc$t8v$1@forums.macromedia.com...
> Thanks David! I had just found that on php.net (that "functions" drop down
> always gets me) and was just trying to figure out syntax - thank you very
> much!!!!
>
> Jon
>
> "David Powers" <david@example.com> wrote in message
> news:e7s9f5$sld$1@forums.macromedia.com...
>> crash wrote:
>>> if $i/2 has a remainder, print right
>>> if $i/2 has no remainder, print left
>>
>> if ($i%2) {
>> // code to float right
>> }
>> else {
>> // code to float left
>> }
>>
>> --
>> David Powers
>> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
>> Author, "Foundation PHP 5 for Flash" (friends of ED)
>> http://foundationphp.com/
>
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2006 Jun 27, 2006
crash wrote:
> works perfectly David, thank you very much!

Glad to have been of help. The modulo operator is one of those things
that makes you wonder "what on earth would anybody want that for?" But
it's actually very useful, particularly because "no remainder" is 0,
which PHP regards as false. Any other number is treated as true, so a
calculation that produces a remainder is always true.

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 27, 2006 Jun 27, 2006
LATEST
On 27 Jun 2006 in macromedia.dreamweaver.appdev, David Powers wrote:

> crash wrote:
>> works perfectly David, thank you very much!
>
> Glad to have been of help. The modulo operator is one of those things
> that makes you wonder "what on earth would anybody want that for?" But
> it's actually very useful, particularly because "no remainder" is 0,
> which PHP regards as false. Any other number is treated as true, so a
> calculation that produces a remainder is always true.

I think that it goes in the 'stupid programmer tricks' category (stupid
modifying tricks, not programmer), but I use it all the time. If you're
not aware of it, however, it can make for inscrutible code.

$othervar = ($myvar%3) ? function1() : function2() ;

Toss in a couple of postfix decrements, and it gets inscrutible. Mind
you, I admire that kind of coding, particularly when I'm doing it...

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines