intelliproject logo

Location: Web development - PHP    License: The Intelliproject Open License (IPOL)

Alternating table rows in PHP

Posted by Thomas Schaefer

Building alternating table rows by using modulo

Skill: Beginner

Posted: 05/12/2008

Views: 591

Rating: 2.50 /5

Popularity: 0.75

Sign Up to vote for this article

Introduction

This piece of code shall beginners show how to use modulo for designing complex formatted table easily.

Important!

Do always begin with the highest increment, when defining the clause, otherwise lower increment clauses will overwrite the higher ones.

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Thomas Schaefer

Location: Germany
Ocupation: Senior Developer and Software Engineer

Posted by Frank at 05/12/2008 16:00
That is a bit too much code for just alternating table rows. It could be done much easier.

I wrote something much simpler (not tested):
http://pastebin.com/f1f741089
Posted by Thomas Schaefer at 06/12/2008 02:59
Hi, Frank. I do know! That was only a test article for me. I wanted to get an image how the CMS is working. ;-8
Posted by Thomas Schaefer at 06/12/2008 03:04
Afterburner: It is for very beginner's. As you know there is a weighing property for articles.
I did not try to write about the aesthestics of agility.
Posted by Thomas Schaefer at 06/12/2008 03:13
After-Afterburner: I just looked at your sample. Before your calling for a shoot out. Read! Then Think! Then Answer! My very beginner's sample is more then your paste to bin sample. Sorry, I just thought that you 'd understood the weirdness of my very beginner's hack! Your sample only formats every second row against a default. My sample very beginner sample is a bit more differentiated. Maybe, you 'll understand when you try it out.
Posted by Thomas Schaefer at 06/12/2008 03:16
3-Times-Afterburner: You can replace the inline style css attributes by css classes easily, if you want to reduce code. So what! This is only a very beginner's demo.
Posted by Thomas Schaefer at 06/12/2008 03:27
4-Times-Afterburner: Alternating does not mean that you only change values every second incremental step. You can build loops for formatting complex table sets; i.e. soccer league tables with a weird coloring set or oversized business index tables.
The goal was to show how modulo works. The secret is ??? (your code: $x % 2, my code: $x % 2==0) Think about it!!!
Posted by Frank at 06/12/2008 08:55
Hehe, it almost sounds like I insulted you. It wasn't my intention. ;)

You should put some comments in the code, makes it more understandable. :)

Sign up to post message on the article message board!