| Subcribe via RSS

Alternating Row Color in PHP

June 25th, 2009 | Comments Off | Posted in CSS, PHP, Uncategorized

In ASP.NET setting the background color for alternating rows is very simply. Just update the property on the Gridview and whalah! Crayola just marked up your database output in pretty colors. In PHP, its not quite as simple, but not terribly complicated either. Basically, we are going to set the odd and even row background colors in our css stylesheet then increment our loop value as we cycle through the records and dynamically populate our class value on the tr for the given row.

Stylesheet

PHP Code

This is a JSON result set we are looping through. The key line to focus on here is row 9 in the PHP code. This appends the i value we’ve been incrementing via the loop to the tr class property. This gives us that clean alternating row look within minimal work.

Tags: , ,

Format DateTime & Currency in ASP.NET from Database Output

June 8th, 2009 | Comments Off | Posted in ASP.NET, Uncategorized

Pretty easy one today. The database is spitting back the datetime stamp as 6/9/2009 12:05:42 AM and you need to drop the time. No problem. We just need to convert the database output to datetime format then set the date format in the ToString function.

This gives us that nice clean format we were looking for. Here are a variety of other options when it comes to formats for the datetime.

If we wanted to format currency, we would place it in the following format:

Tags: , ,