RE: [PHP] Re: Table formatting

From: Date: Sat, 27 Jul 2002 07:43:53 +0000
Subject: RE: [PHP] Re: Table formatting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109988@lists.php.net to get a copy of this message
I'd use the following code: ------------------------------ // DB QUERY $query = "SELECT columnFirst, columnSecond, columnThird FROM table_name"; $result = mysql_query($query) or die(mysql_error()); // NOW THE LOOP while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>"; echo join("</td><td>", $row); echo "</td>"; echo "</tr>"; }; ------------------------------ -----Oorspronkelijk bericht----- Van: Chris Earle [mailto:chris@earleweb.com] Verzonden: 27 July 2002 06:54 Aan: php-general@lists.php.net Onderwerp: [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" <icaam@icaam.com.ar> wrote in message 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:webmaster@icaam.com.ar> 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

« previous php.general (#109988) next »