Two for { }

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

    Two for { }

    Hi friends!!!

    I'm stuck with something. I want to show some pictures in my site. Max
    5 pictures in a row and start a new row. The number of rows must by the
    total numbers of pictures available through the "select" divided by 5
    and applied the ceil function to round up the result. So, I have the
    total number of rows to show. ok, now I have the problem and I copy the
    code to ask you for help. The result of the followin code is the first
    pictures repeated indefinitely.

    Thank you very much!

    Ezequiel


    $response = mysql_query("se lect * from fotografias where decada=1970",
    $dbase);
    if (!$response) {
    die('Invalid query: ' . mysql_error());
    }
    $cantidad= mysql_num_rows( $response);
    $hasta=ceil($ca ntidad/5);
    echo('<center>' );
    while($row = mysql_fetch_arr ay($response))
    {
    for ($i=0;$i=$hasta ;$i++)
    {
    for ($j=1;$j=5;$j++ )
    {
    echo('<img src="' .$row[url]. '" border="0">');
    }
    echo('<br>');
    }

    }

  • Jonathan

    #2
    Re: Two for { }

    zek2005 wrote:

    <snip>
    [color=blue]
    > while($row = mysql_fetch_arr ay($response))
    > {
    > for ($i=0;$i=$hasta ;$i++)
    > {
    > for ($j=1;$j=5;$j++ )
    > {
    > echo('<img src="' .$row[url]. '" border="0">');
    > }
    > echo('<br>');
    > }
    >
    > }
    >[/color]

    You are running the mysql_fetch_arr ay command outside the loop
    generating the table.

    You might want to take a look at this thread as weel as it is almost the
    same problem:
    http://groups.google.c om/group/comp.lang.php/browse_thread/thread/7f1b231106540c7 a/d47992731bf1bcc 2?lnk=st&q=Need +help+with+my+c ode+reading+fla t+file+into+HTM L+table&rnum=1# d47992731bf1bcc 2

    Jonathan

    Comment

    • d

      #3
      Re: Two for { }

      "zek2005" <esapoznik@gmai l.com> wrote in message
      news:1137958840 .688392.165190@ z14g2000cwz.goo glegroups.com.. .[color=blue]
      > Hi friends!!!
      >
      > I'm stuck with something. I want to show some pictures in my site. Max
      > 5 pictures in a row and start a new row. The number of rows must by the
      > total numbers of pictures available through the "select" divided by 5
      > and applied the ceil function to round up the result. So, I have the
      > total number of rows to show. ok, now I have the problem and I copy the
      > code to ask you for help. The result of the followin code is the first
      > pictures repeated indefinitely.
      >
      > Thank you very much!
      >
      > Ezequiel
      >
      >
      > $response = mysql_query("se lect * from fotografias where decada=1970",
      > $dbase);
      > if (!$response) {
      > die('Invalid query: ' . mysql_error());
      > }
      > $cantidad= mysql_num_rows( $response);
      > $hasta=ceil($ca ntidad/5);
      > echo('<center>' );
      > while($row = mysql_fetch_arr ay($response))
      > {
      > for ($i=0;$i=$hasta ;$i++)
      > {
      > for ($j=1;$j=5;$j++ )
      > {
      > echo('<img src="' .$row[url]. '" border="0">');
      > }
      > echo('<br>');
      > }
      >
      > }[/color]

      Why don't you just loop through all the pictures in one loop, and use "$i %
      $columns" to figure out when to start and end a new row. None of that
      loops-within-loops stuff ;)


      Comment

      Working...