From: Ashley Sheridan on 28 Apr 2010 09:44 On Wed, 2010-04-28 at 09:46 -0400, Fernando wrote: > But then you need to differentiate the table, otherwise all your tables > will have the same row formating no? This way you only apply the > formating to those rows that need it. > > Fernando. > > On 28/04/2010 09:35, Ashley Sheridan wrote: > > On Wed, 2010-04-28 at 09:34 -0400, Fernando wrote: > > > > > >> What about this: > >> > >> $color = "even"; > >> while ($row = while condition )) { > >> $color = ($color == "even") ? "odd" : "even"; > >> echo ("<tr class=\"$color\">"); > >> echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td><td>$row[3]</td><td>$row[4]</td> "; > >> echo ("</tr>") > >> } > >> > >> And have two classes in your style sheet that format each row differently. > >> > >> Hope this helps. > >> > >> > >> On 28/04/2010 09:29, Ali Asghar Toraby Parizy wrote: > >> > >>> I agree with you. in this simple example we can use php but we may need > >>> table with extra functionality and only client side scripts are reasonable > >>> and applicable. we can create multi color and clickable rows by php but > >>> we'll have greater server load. > >>> anyway that was only an propose;-) > >>> > >>> On Wed, Apr 28, 2010 at 4:12 PM, Ashley Sheridan > >>> <ash(a)ashleysheridan.co.uk>wrote: > >>> > >>> > >>> > >>>> On Wed, 2010-04-28 at 16:16 +0430, Ali Asghar Toraby Parizy wrote: > >>>> > >>>> It isn't good idea to use php to visualize your table. You can fetch > >>>> you data by php and style them by java script. > >>>> > >>>> On Wed, Apr 28, 2010 at 3:59 PM, Juan Rodriguez Monti > >>>> <juan(a)rodriguezmonti.com.ar> wrote: > >>>> > >>>> > >>>>> Hello Guys, > >>>>> I would like to implement a two color row table for some queries that I'm doing. > >>>>> > >>>>> I use PHP to query a DB, then I use while to print all its results. I > >>>>> have a code pretty similar to this one : > >>>>> > >>>>> $results = Here the QUERY; > >>>>> echo "<html>"; > >>>>> echo "<head>"; > >>>>> echo '<link rel="stylesheet" type="text/css" href="style.css" />'; > >>>>> echo "</head>"; > >>>>> echo "<body>"; > >>>>> echo '<div id="container">'; > >>>>> > >>>>> echo "<center><h2>Results</h2></center><br />"; > >>>>> echo ("<table border='1'>"); > >>>>> echo "<td><strong>At1</strong></td> > >>>>> <td><strong>At2</strong></td> <td><strong>At3</strong></td> $ > >>>>> > >>>>> while ($row = while condition )) { > >>>>> echo ("<tr>"); > >>>>> echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td> > >>>>> <td>$row[3]</td><td>$row[4]</td> "; > >>>>> echo "</div>"; > >>>>> echo "</body>"; > >>>>> echo "</html>"; > >>>>> > >>>>> I just want to show you how I write the table. What I would like to > >>>>> know is what do you suggest to do a two color row format. > >>>>> > >>>>> Thanks!, > >>>>> Juan > >>>>> > >>>>> -- > >>>>> PHP General Mailing List (http://www.php.net/) > >>>>> To unsubscribe, visit: http://www.php.net/unsub.php > >>>>> > >>>>> > >>>>> > >>>>> > >>>> > >>>> Javascript is even less of a good idea, as it can be turned off and isn't > >>>> available on all browsers. PHP doesn't rely on the clients browser, so is a > >>>> safer bet. > >>>> > >>>> > >>>> Thanks, > >>>> Ash > >>>> http://www.ashleysheridan.co.uk > >>>> > >>>> > >>>> > >>>> > >>>> > >>> > >>> > > > > You really only need one alternate row class, as I showed in my earlier > > example. All the rows are styled using the tables default CSS, and then > > you just style the rows you want to change from that default. Here it is > > again :p > > > > http://www.ashleysheridan.co.uk/coding_php_alternate_rows.php > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > > > > Yes, but one would assume you'd be doing that anyway if you needed this table to be displayed differently from all the others on your page? Thanks, Ash http://www.ashleysheridan.co.uk
From: Juan Rodriguez Monti on 28 Apr 2010 09:58 2010/4/28 Fernando <fernando(a)ggtours.ca>: > What about this: > > $color = "even"; > while ($row = while condition )) { > $color = ($color == "even") ? "odd" : "even"; > echo ("<tr class=\"$color\">"); > echo "<td>$row[0]</td><td>$row[1]</td> > <td>$row[2]</td><td>$row[3]</td><td>$row[4]</td> "; > echo ("</tr>") > } > > And have two classes in your style sheet that format each row differently.. > > Hope this helps. Thanks to all guys!. Now it's working perfectly as I wanted. Also was interesting to read the points you showed about JS and PHP. Best, Juan
From: "Bob McConnell" on 28 Apr 2010 10:02 From: Ashley Sheridan > On Wed, 2010-04-28 at 09:46 -0400, Fernando wrote: > >> But then you need to differentiate the table, otherwise all your tables >> will have the same row formating no? This way you only apply the >> formating to those rows that need it. > > Yes, but one would assume you'd be doing that anyway if you needed this > table to be displayed differently from all the others on your page? The alternate colors should be in a CSS style linked to the TR tag. The base table style is used for the odd rows, with the alternate colors for the even rows. It's very easy to create multiple variations that way. Javascript is definitely out. Only a fool or an imbecile intentionally enables primary malware infection vectors like that. I believe Firefox should install the NoScript add-on by default with maximum protection enabled. Bob McConnell
From: Richard Quadling on 28 Apr 2010 10:33 On 28 April 2010 12:29, Juan Rodriguez Monti <juan(a)rodriguezmonti.com.ar> wrote: > Hello Guys, > I would like to implement a two color row table for some queries that I'm doing. > > I use PHP to query a DB, then I use while to print all its results. I > have a code pretty similar to this one : > > Â $results = Here the QUERY; > Â Â Â Â echo "<html>"; > Â Â Â Â echo "<head>"; > Â Â Â Â echo '<link rel="stylesheet" type="text/css" href="style.css" />'; > Â Â Â Â echo "</head>"; > Â Â Â Â echo "<body>"; > Â Â Â Â echo '<div id="container">'; > > Â Â Â Â echo "<center><h2>Results</h2></center><br />"; > Â Â Â Â echo ("<table border='1'>"); > Â Â Â Â echo "<td><strong>At1</strong></td> > <td><strong>At2</strong></td> <td><strong>At3</strong></td> Â Â Â $ > > Â while ($row = while condition )) { > Â Â Â Â echo ("<tr>"); > Â Â Â Â echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td> > <td>$row[3]</td><td>$row[4]</td> "; > Â Â Â Â echo "</div>"; > Â Â Â Â echo "</body>"; > Â Â Â Â echo "</html>"; > > I just want to show you how I write the table. What I would like to > know is what do you suggest to do a two color row format. > > Thanks!, > Juan > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > As everyone and their dog has a way ... My loop contains ... $Odd = $Odd ? '' : ' class="odd"'; $Rows .= <<< END_HTML_ROW <tr $Odd> <th>{$RemovalReason->UniqueID}</th> <td>{$RemovalReason->RemovalReason}</td> <td>{$RemovalReason->DateAdded}</td> <td>{$RemovalReason->DateRemoved}</td> </tr> END_HTML_ROW; So, the table has a standard style and odd rows are tagged as odd. This doesn't style the rows directly, just tags the odd rows. Using CSS, you can now construct different styles for odd rows for this table. If you want to have more than 1 table on a page, each with a different style, then fine. Just use appropriate CSS rules. tbody tr { background: url(bg_td1.jpg) repeat-x top; } tbody tr.odd { background: #FFF8E8 url(bg_td2.jpg) repeat-x; } for example, for all normal rows. Add a #ID to that for specific tables, etc. No JS. Minimal html. -- ----- Richard Quadling "Standing on the shoulders of some very clever giants!" EE : http://www.experts-exchange.com/M_248814.html EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 ZOPA : http://uk.zopa.com/member/RQuadling
From: tedd on 29 Apr 2010 09:10
At 8:29 AM -0300 4/28/10, Juan Rodriguez Monti wrote: >Hello Guys, >I would like to implement a two color row table for some queries >that I'm doing. > >I use PHP to query a DB, then I use while to print all its results. I >have a code pretty similar to this one : > > $results = Here the QUERY; > echo "<html>"; > echo "<head>"; > echo '<link rel="stylesheet" type="text/css" href="style.css" />'; > echo "</head>"; > echo "<body>"; > echo '<div id="container">'; > > echo "<center><h2>Results</h2></center><br />"; > echo ("<table border='1'>"); > echo "<td><strong>At1</strong></td> ><td><strong>At2</strong></td> <td><strong>At3</strong></td> $ > > while ($row = while condition )) { > echo ("<tr>"); > echo "<td>$row[0]</td><td>$row[1]</td> <td>$row[2]</td> ><td>$row[3]</td><td>$row[4]</td> "; > echo "</div>"; > echo "</body>"; > echo "</html>"; > >I just want to show you how I write the table. What I would like to >know is what do you suggest to do a two color row format. > >Thanks!, >Juan Juan: Everyone has done this at one time or another -- this is my solution. http://webbytedd.com/b/color-rows/ Plus, it validates and keeps things simple. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |