Easy if....question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eze

    Easy if....question

    Hi!!!!

    I need to create a table of 4 columns x n rows. The number of row will
    depend on the number of images for that specific page.

    I think that I have to use de mod function saying that if (number of
    image mod 4 equal 0 then start another row)

    Well....first thing...I find the function fmod in the help that I
    think that will be useful.

    I wrote this small code, but it does not work

    while($row = mysql_fetch_arr ay($respuesta))
    {
    echo('<td width=15% align="center"> <img src=" ' .$row["url"]. '
    "></td>');
    $i++;
    if (fmod ($i,4)==0)
    {
    <tr>
    }
    }

    Anyone can help me?

    Thanks in advance

    Ezequiel
  • Jan Pieter Kunst

    #2
    Re: Easy if....question

    In article <e11a3cdf.04041 70835.4da88b88@ posting.google. com>,
    esapoznik@hotma il.com (Eze) wrote:
    [color=blue]
    > I think that I have to use de mod function saying that if (number of
    > image mod 4 equal 0 then start another row)[/color]

    It seems simpler to me to just check if the number is equal to 4, and if
    it is, reset it to zero again.

    $i = 0;
    while($row = mysql_fetch_arr ay($respuesta)) {
    if ($i < 4) {
    do_something();
    $i++;
    } elseif ($i == 4) {
    do_something_el se();
    $i = 0;
    }
    }

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Tom Thackrey

      #3
      Re: Easy if....question


      On 17-Apr-2004, esapoznik@hotma il.com (Eze) wrote:
      [color=blue]
      > I need to create a table of 4 columns x n rows. The number of row will
      > depend on the number of images for that specific page.
      >
      > I think that I have to use de mod function saying that if (number of
      > image mod 4 equal 0 then start another row)
      >
      > Well....first thing...I find the function fmod in the help that I
      > think that will be useful.
      >
      > I wrote this small code, but it does not work
      >
      > while($row = mysql_fetch_arr ay($respuesta))
      > {
      > echo('<td width=15% align="center"> <img src=" ' .$row["url"]. '
      > "></td>');
      > $i++;
      > if (fmod ($i,4)==0)
      > {
      > <tr>
      > }
      > }
      >
      > Anyone can help me?[/color]

      You have several problems. The fmod() or % will work, I find counting
      easier. Your HTML is wrong (spaces in the src= parm for example). The <tr>
      in the if needs an echo or something.

      This should be close (untested):

      echo '<table>';
      $i = 0;
      while($row = mysql_fetch_arr ay($respuesta))
      {
      if ($i==4)
      {
      echo '</tr><tr>';
      $i=0;
      }
      echo '<td width="15%" align="center"> <img src="' .$row["url"]. '"></td>';
      $i++;
      }
      while($i<4)
      {
      echo '<td> </td>';
      $i++;
      }
      echo '</tr></table>';


      --
      Tom Thackrey

      tom (at) creative (dash) light (dot) com
      do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

      Comment

      • Five Cats

        #4
        Re: Easy if....question

        In message <7gigc.23633$gO 1.8706@newssvr2 7.news.prodigy. com>, Tom
        Thackrey <use.signature@ nospam.com> writes[color=blue]
        >You have several problems. The fmod() or % will work, I find counting
        >easier. Your HTML is wrong (spaces in the src= parm for example). The
        ><tr> in the if needs an echo or something.
        >
        >This should be close (untested):
        >
        >echo '<table>';[/color]

        echo '<tr>';
        [color=blue]
        >$i = 0;
        >while($row = mysql_fetch_arr ay($respuesta))
        >{
        > if ($i==4)
        > {
        > echo '</tr><tr>';
        > $i=0;
        > }
        > echo '<td width="15%" align="center"> <img src="' .$row["url"].
        >'"></td>';
        > $i++;
        >}
        >while($i<4)
        >{
        > echo '<td> </td>';
        > $i++;
        >}
        >echo '</tr></table>';[/color]

        --
        Five Cats
        Email to: cats_spam at uk2 dot net

        Comment

        Working...