Jump to content

Multiple of 4


atlanta

Recommended Posts

different ways

always check if $num has a value (if 0 ya will get an error, divide by zero)

 

if($num && (($num/4)==intval($num/4))  { echo true; } else { echo false; }

 

or

 

if($num && !($num % 4)) { echo true; } else { echo false; }

 

I even think this one will work

if (!( 3 & $num)) { echo true; } else { echo false; }

 

note on the last one, no $num check is done. prolly the fastest as well, since no division is needed :) but dusn work on floats, just integers.

 

Link to comment
Share on other sites

Hey another quick question ok i got the the <tr> to show on every multiple of 4 but how do i make the </tr> show on every count of 4 with starting at 0??

 

if ($cnt == "0" || ($cnt % 4) == 0)
{
echo "<tr>";
}
?>
<td>
       <a href="<?php echo $urlpath . $file; ?>" target="_blank" rel="lightbox[album]" title="<?=$exten[0]?>">
      <img src="<?php echo $urlpath . $file; ?>" alt="<?=$exten[0]?>" width="158" height="168" />
       </a>
</td>
<?
if (function??)
{
echo "</tr>";
}
?>

Link to comment
Share on other sites

Here maybe this will help if i added all the code its kinda confusing without it

 

if(isset($_GET['folder']))
{
?>
<table class="phototable">
<?
for ($cnt = $start; $cnt < $end; $cnt++) {
    $file = $files[$cnt];

    $exten = explode('.',$file);

if ($cnt == "0" || ($cnt % 4) == 0)
{
echo "<tr>";
}
?>
<td>
       <a href="<?php echo $urlpath . $file; ?>" target="_blank" rel="lightbox[album]" title="<?=$exten[0]?>">
      <img src="<?php echo $urlpath . $file; ?>" alt="<?=$exten[0]?>" width="158" height="168" />
       </a>
</td>
<?
if ($cnt == "3" || $cnt == "7" || $cnt == "11")
{
echo "</tr>";
}
?>

<?
} // end for
?>
<?
} // end if

 

ok so what i want to do is have it eacho </tr> on every 4th count you get me ?

so that after the forth coloumn it will start a new row

Link to comment
Share on other sites

lol

 

i think i said using the booleans was prolly easiest.

 

since 4 is a magic number, in the word of bits

 

<?php
  echo "<TABLE border=1>";
  for($i=0;$i<=20;$i++)
  {
if(!($i & 3)) echo "<tr>";
echo "<td>$i</td>";
if(($i & 3)==3) echo "</tr>";
  }
  if(($i&=3)) echo "<TD COLSPAN=". (4-$i) ."> </TD></TR>";
  echo "</table>";
  
?>

Link to comment
Share on other sites

You are going to kick yourself for not realizing this.

 

Change this:

 

if ($cnt == "0" || ($cnt % 4) == 0)
{
echo "<tr>";
}

 

To this:

 

if ($cnt == "0" || ($cnt % 4) == 0)
{
echo "</tr><tr>";
}

 

This will end the previous row and start the next one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.