why would you expect a for loop to know whether there was an array returned
from the mysql_fetch_array($result). you haven't told it to check this. This
is why I suggested using the fetch_array() to control the loop and a counter
to determine when to start and end rows - did you not get that?


        Tim Ward
        www.chessish.com

> -----Original Message-----
> From: CÚsar Aracena [mailto:[EMAIL PROTECTED]]
> Sent: 29 July 2002 16:39
> To: 'Martin Towell'; [EMAIL PROTECTED]
> Subject: RE: [PHP] Re: Table formatting <-- PARTIALY SOLVED
> 
> 
> Thnx a lot Martin and all, this worked. Anyway, apart of this being a
> logical solution (I almost kill myself for not thinking it 
> before), why
> is that the FOR looping (before using that division operator) 
> worked in
> such a strange way? Isn't it supposed to stop looping if 
> nothing else is
> fetched from the DB?
> 
> Pardon my interest in learning, but this is how I am.
> 
> Thanks a lot, C.
> 
> > -----Original Message-----
> > From: Martin Towell [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, July 29, 2002 2:05 AM
> > To: 'CÚsar Aracena'; [EMAIL PROTECTED]
> > Subject: RE: [PHP] Re: Table formatting
> > 
> > try changing these two lines
> > 
> > $num_rows = mysql_num_rows($result);
> > $num_cols = 2;
> > 
> > to this
> > 
> > $num_cols = 2;
> > $num_rows = mysql_num_rows($result) / $num_cols;
> > 
> > this isn't the full solution, but will help you on your way...
> > 
> > HTH
> > Martin
> > 
> > -----Original Message-----
> > From: CÚsar Aracena [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, July 29, 2002 2:03 PM
> > To: [EMAIL PROTECTED]
> > Subject: RE: [PHP] Re: Table formatting
> > 
> > 
> > I know no one in this list like to think we newbie's want 
> the job done
> > for us, so I'm trying to figure out the below question myself, but
> trust
> > me when I say it's making me nuts... this is my best shot so far:
> > 
> > $query = "SELECT * FROM saav_arts ORDER BY artid";
> > $result = mysql_query($query) or die(mysql_error());
> > $num_rows = mysql_num_rows($result);
> > $num_cols = 2;
> > 
> > for ($x = 0; $x < $num_rows; $x++)
> > {
> >     echo "<tr>";
> > 
> >     for ($i = 0; $i < $num_cols; $i++)
> >     {
> > 
> >             $row = mysql_fetch_array($result);
> >             echo "<td align=\"center\">";
> >             echo "<a href=\"details.php?artid=".$row[artid]."\"><img
> > src=\"".$CFG->artdir."/".$row[artsmall]."\"
> > ALT=\"".$row[artname]."\" BORDER=\"0\"></a>";
> >             echo "</td>";
> >     }
> > 
> >     echo "</tr>";
> > }
> > 
> > The thing is that it shows up two columns as I want, but not the 4
> > images that I have in DB... it shows 2 rows of 2 images each and
> antoher
> > 2 rows of 2 *NOT DIPLAYED* images which I don't have... like it was
> > looping again with nothing to fetch from the DB... What is this?
> > 
> > Jason: as I wrote this, your tip came over and as you can see I did
> > figure it out (almost melted my brain though)... now, do 
> you know what
> > is going on?
> > 
> > Thanx, C.
> > 
> > > -----Original Message-----
> > > From: CÚsar Aracena [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, July 29, 2002 12:27 AM
> > > To: 'Chris Earle'; [EMAIL PROTECTED]
> > > Subject: RE: [PHP] Re: Table formatting
> > >
> > > I like this method a lot. Now, considering I do like FOR 
> looping as
> a
> > > fact, how can I make a loop inside another loop. I mean, if I tell
> the
> > > first loop that $i=0 and then do the comparison and then add 1 to
> $i,
> > in
> > > the inner or second loop should I state that $i=$i or what? Also
> make
> > it
> > > $i=0???
> > >
> > > Thanks, C.
> > >
> > > > -----Original Message-----
> > > > From: Chris Earle [mailto:[EMAIL PROTECTED]]
> > > > Sent: Saturday, July 27, 2002 1:54 AM
> > > > To: [EMAIL PROTECTED]
> > > > Subject: [PHP] Re: Table formatting
> > > >
> > > > You can do what he said or just put a separate loop inside the
> > > original
> > > > loop.
> > > >
> > > > Depending on how you get the info, you can use either way (his
> would
> > > > create
> > > > less overhead if you are just using the same <TD> info 
> every row,
> > > > otherwise
> > > > they're really the same because his way you'll have to create an
> > array
> > > to
> > > > access later for multiple rows, or just do my way and have the
> loop
> > > access
> > > > the NEXT *3* (or whatever) items ...).
> > > >
> > > > i.e.,
> > > > for (LOOP FOR <TR>)
> > > > {
> > > >     for (LOOP FOR <TD>) {}
> > > > }
> > > >
> > > > "CÚsar aracena" <[EMAIL PROTECTED]> wrote in message
> > > > 001a01c234f0$a5e8ad80$28ed0dd1@gateway">news:001a01c234f0$a5e8ad80$28ed0dd1@gateway...
> > > > Hi all.
> > > >
> > > > Last nite I've came across a problem I wasn't able to figure out
> by
> > my
> > > > self. It's not difficult to make a loop that will make 
> new *TABLE
> > > ROWS*
> > > > (<tr>) to show several DB objects in a nice way. what I need to
> do,
> > is
> > > > to display 2 or maybe even 3 of this objects stored in a DB per
> > table
> > > > row, separated in different *TABLE COLUMS* (<td>). how can I
> achieve
> > > > this? What I usually do is:
> > > >
> > > > ------------------------------
> > > > // DB QUERY
> > > > $query = "SELECT * FROM table_name";
> > > > $result = mysql_query($query) or die(mysql_error());
> > > > $num_rows = mysql_num_rows($result);
> > > >
> > > > // NOW THE LOOP
> > > > for ($i=0; $i<$num_rows; $i++)
> > > > {
> > > >      $row = mysql_fetch_array($result);
> > > >      echo "<tr>";
> > > >      echo "<td>";
> > > >      echo $row[whatever];
> > > >      echo "</td>";
> > > >      echo "</tr>";
> > > > }
> > > > ------------------------------
> > > >
> > > > but how can I get 2 or 3 columns displaying different 
> db objects?
> A
> > > loop
> > > > inside a loop?
> > > >
> > > > Thanks in advance,
> > > >
> > > >  <mailto:[EMAIL PROTECTED]> Cesar Aracena
> > > > CE / MCSE+I
> > > > Neuquen, Argentina
> > > > +54.299.6356688
> > > > +54.299.4466621
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> > 
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to