php4-beta | 200004
Date: 04/27/00
- Next message: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Previous message: Bradley: "[PHP4BETA] A (Hopefully) simple question *gulp*"
- In reply to: Bradley: "[PHP4BETA] A (Hopefully) simple question *gulp*"
- Next in thread: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: John Steele: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 28 Apr, Bradley wrote:
> Hi guys, I sent this bit of code here a while back and everyone was
> REALLY helpful. I'm hoping to get the same sort of results this time
> (fingers crossed).
>
> I use this snippet to display the rows of a user-configured select in
> a table format.
>
> "
> elseif ($disp)
> {
>
> if ($subcats == "All") {
>
> $result = mysql_query("SELECT $sources FROM $catty",$db);
> } else {
>
> $result = mysql_query("SELECT $sources FROM $catty WHERE SubCategory =
> '$subcats' order by $sorter",$db); echo ">> $subcats $catty Query
> sorted by $sorter<br>"; echo "<table cellspacing=\"2\"
> class=\"narea\">"; echo "<tr>\n"; echo "<td
> valign=\"center\">ID</td><td align=\"center\"
> valign=\"center\">Dept</td><td>Category</td><td>Sub-Category</td><td>Description</td><td>Make</td><td>Model</td><td>Model
Number</td><td>Serial Number</td><td>Date Acq'd</td><td>Vendor</td>\n";
> echo "</tr>\n";
>
> while ($row = mysql_fetch_row($result)){
> echo "<tr bgcolor=\"#00AAAA\">";
>
> // The next bit turns the id number into a link to edit the properties
> // // of the line item. It uses the javascript from way back in the
> beginning // // of the script to popup a little editing window //
>
> for ($p = 0;$p < count($row);$p++) {
> if ($p == 0) {
> echo "<td><font size=\"2\" face=\"arial, helvetica\">";
>
> echo "<a
> href='javascript:openPopWin(\".//update/update.php?id=$row[$p]&catty=$catty\",
400, 400, \"\", 1, 1)'>$row[$p]</a>";
>
> } else {
> echo "<td><font size=\"2\" face=\"arial, helvetica\">
> $row[$p]</font></td>"; echo "</tr>";
>
> "
>
> and it works BRILLIANTLY. Here comes the question. I've seen a lot of
> tables built in php with alternating row colors. Most notably
> phpmyadmin and freshmeat.net. What I mean is, the first row is a
> certain color, then the second row is a second color, the third row
> goes back to the original color...and so on and so forth.
>
> Is there a relatively simple way to do this? If I have to, I suppose I
> could try and dismantle the phpmyadmin code (wouldn't be the first
> time.. =) but I'd rather not as there are a lot of things there that I
> don't need.
>
> Ideas anyone?
>
> TIA,
>
> Bradley
Yup. Initialise a counter then increment it for each table row you
display. Then, on each row, test the counter value mod 2. If the result
is zero, use one colour for row background, otherwise use the other
colour.
You could use several colours if you wanted by expanding the range of
mod results you test for - eg for 3 colours you'd test for counter mod 3
values of 0, 1 or 2
The actual code is left as an exercise for the reader :-)
PS Sorry about the potentially screwed up line wrapping in the cite, but
if you could convince your mailer to wrap at around 72 characters.....
Cheers
-- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA-- PHP 4.0 Beta Mailing List <http://www.php.net/version4/> To unsubscribe, e-mail: php4beta-unsubscribe <email protected> For additional commands, e-mail: php4beta-help <email protected> To contact the list administrators, e-mail: php4beta-admin <email protected>
- Next message: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Previous message: Bradley: "[PHP4BETA] A (Hopefully) simple question *gulp*"
- In reply to: Bradley: "[PHP4BETA] A (Hopefully) simple question *gulp*"
- Next in thread: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: Bradley: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Reply: John Steele: "Re: [PHP4BETA] A (Hopefully) simple question *gulp*"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

