SV: [PHP-DB] Results with ledger stripes?

From: Date: Mon, 26 Jan 2004 12:38:04 +0000
Subject: SV: [PHP-DB] Results with ledger stripes?
Groups: php.db 
Request: Send a blank email to php-db+get-32624@lists.php.net to get a copy of this message
Or even simpler: echo "<table><tr><td>Domain</td><td>Average Speed</td></tr>\n"; while ($mongorow = mysql_fetch_row($mongo, MYSQL_NUM)) { $color = ("#e4e4e4")? "#ffffff" : "#e4e4e4"; echo "<tr bgcolor=$color><td>$mongorow[0]</td><td>$mongorow[1]</td></tr>\n"; } echo "</table>"; Regards Henrik Hornemann -----Oprindelig meddelelse----- Fra: Paul Fitz [mailto:pfitz@dodo.com.au] Sendt: 26. januar 2004 12:34 Til: 'PHP DB' Emne: RE: [PHP-DB] Results with ledger stripes? Hi, You can use the modulus operator to create alternate colour rows. A bit simpler in code ;) See below - -------------------------------------------- echo "<table><tr><td>Domain</td><td>Average Speed</td></tr>\n"; // Define count variable which is tested in loop $count = 1; while ($mongorow = mysql_fetch_array($mongo, MYSQL_NUM)) { // If $count divides evenly by 2, white, if not then #efefef $color = ($count % 2)? "#ffffff" : "#e4e4e4"; echo "<tr bgcolor=$color><td>$mongorow[0]</td><td>$mongorow[1]</td></tr>\n"; $count++; } echo "</table>"; --------------------------------------------------- // Done :) -----Original Message----- From: Ricardo Lopes [mailto:lopes@elevaconsult.pt] Sent: Monday, January 26, 2004 7:29 PM To: dan@dibcomputers.com Cc: PHP DB Subject: Re: [PHP-DB] Results with ledger stripes? I dont see what is your problem, your code do almost anything. Is you pretend to generate the output in html as you show in the example, you just have to add the color property in the "td" or "tr" tag, take care with the " in the code. ex: $dummy_var = 0; $dummy_array = array("#dddddd", "#ffffff"); while ($mongorow = mysql_fetch_array($mongo, MYSQL_NUM)) { echo "<tr bgcolor= ".$dummy_array[$dummy_var]."><td>$mongorow[0]</td><td>$mongorow[1]</td>< /tr> \n"; $dummy_var++; } And thats is it. You could use css or other things, thats up to you. Hope thats solved. ----- Original Message ----- From: <dan@dibcomputers.com> To: <php-db@lists.php.net> Sent: Monday, January 26, 2004 1:42 AM Subject: [PHP-DB] Results with ledger stripes? > Hello all, > > I'm in the midst of creating an internet speed test system thingamabob for > my website. It's basically finished...but ugly as sin. What I'd like to do > is have the results (an average of each domain tested) listed in a nice > pretty table with alternating background colors, kinda like a ledger. How > on earth do I do this? > > Here's what I've got thus far: > > <?php > echo "Average speeds of each domain tested:<br>"; > $mongo = @mysql_query ("SELECT > substring_index(name,'.',-2),ROUND(AVG(speed),1) FROM > readings GROUP BY > substring_index(name,'.',-2) ORDER BY substring_index(name,'.',-2) ASC"); > echo "<table><tr><td>Domain</td><td>Average > Speed</td></tr>\n"; while > ($mongorow = mysql_fetch_array($mongo, MYSQL_NUM)) { echo > > "<tr><td>$mongorow[0]</td><td>$mongorow[1]</td></tr>\n";} > echo "</table>"; > ?> > > And I'd like it to spit out something along these lines: <table> > <tr bgcolor=#dddddd><td>domain1.com</td><td>666.6 > kbps</td></tr> > <tr bgcolor=#ffffff><td>domain2.com</td><td>3000.0 > kbps</td></tr> > repeat until done > </table> > > The gizmo is up and running at > http://www.dibcomputers.com/bandwidthmeter/index.php if you > care to have a > gander. > Thanks a bunch, > Dan > > ------------------------------------------------------------------------ ---- ---- > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#32624) next »