473,770 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[SOLVED] Using CSS class to color alternate rows

2 New Member
I am trying to use a CSS class called "evens" to color the background of alternate rows of a dynamic table. The foreach statement is preventing the data from being displayed at all. If I take it out, I have no problem generating the table. What is the proper way to do this?

=============== ======
// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5" border="0">
<tr>
<td align="left"><s trong>Edit</strong></td>
<td align="left"><s trong>Delete</strong></td>
<td align="left"><s trong>Award Title</strong></td>
<td align="left"><s trong>Award Category</strong></td>
<td align="left"><s trong>Award Text</strong></td></tr>';

// Fetch and print all records.
while ($row = mysql_fetch_arr ay ($result, MYSQL_ASSOC)) {

$n = 0;
foreach($result as $row) {
$theclass = ($n++ % 2) ? 'evens' : '';

echo '<tr class="' . $theclass .'">';
echo '<td align="left"><a href="edit_awar ds.php?id=' . $row['awardID'] . '">Edit</a></td>';
echo '<td align="left"><a href="delete_aw ards.php?id=' . $row['awardID'] . '">Delete</a></td>';
echo '<td align="left"><s pan class="award_ti tle">' . $row['awardTitle'] . '</span></td>';
echo '<td align="left">' . $row['awardCat'] . '</td>';
echo '<td align="left">' . $row['awardText'] . '</td>';
echo '</tr>';
}

}
=============== ======

Any ideas? TIA.
Oct 24 '06 #1
1 2470
pixelnate
2 New Member
Nevermind. I found out a useful tip at the Practical Web Design mag site, and deduced the rest for myself.

Fixed code:
=============== ====
// Table header.
echo '<table align="center" cellspacing="0" cellpadding="5" border="0">
<tr>
<td align="left"><s trong>Edit</strong></td>
<td align="left"><s trong>Delete</strong></td>
<td align="left"><s trong>Award Title</strong></td>
<td align="left"><s trong>Award Category</strong></td>
<td align="left"><s trong>Award Text</strong></td></tr>';

// Fetch and print all records.
$n = 0;
while ($row = mysql_fetch_arr ay ($result, MYSQL_ASSOC)) {

$theclass = ($n++ % 2) ? 'evens' : '';

echo '<tr class="' . $theclass .'">';
echo '<td align="left"><a href="edit_awar ds.php?id=' . $row['awardID'] . '">Edit</a></td>';
echo '<td align="left"><a href="delete_aw ards.php?id=' . $row['awardID'] . '">Delete</a></td>';
echo '<td align="left"><s pan class="award_ti tle">' . $row['awardTitle'] . '</span></td>';
echo '<td align="left">' . $row['awardCat'] . '</td>';
echo '<td align="left">' . $row['awardText'] . '</td>';
echo '</tr>';

}
=============== =========

It now works like a charm. Thanks anyway.
Oct 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6194
by: Ralph Snart | last post by:
Is there a way to alternate table row colors without using the position() mod 2 trick? I'm in a series of nested xsl:for-each elements, about 3 deep, and I want to alternate the table row color all the way through. position() resets to 1 whenever the inner for-each loops around, of course. Example code: <xsl:for-each select="/games/game) = 1]"> <xsl:sort select="platform"/>
1
1678
by: F. Da Costa | last post by:
Hi, In the html (as shown below) there are some <a> tags I need to move into a map. This is no problem (in Gecko) using the js below. However, IE 5+ (nor 6) does not want to play. It gives me an "undefined" error and basically does not give me the objects I expect. Undoubtfully one *can* get a hold of these objects and obviously this is the question. How does one do this in IE??
23
5184
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
4
2284
by: sconeek | last post by:
Hi all, I am generating a html based table with multiple rows of data coming in real time from a postgres DB. The underlying technology is java based however the front end is html. now i am unable to alternate the colour of every row so that the table is lot more readable. can anyone suggest a javascript or even a css script which will alternate the row colours irrespective of the number of rows.
3
2535
by: bob.herbst | last post by:
I have been trying to use HTML_Table from PEAR to write a PHP script that will access a database and retrieve my data into an HTML table that can be sorted by column. Currently I am using the script below, which does not include sorting (I want the basic table to work first) but all I get is the column headers and no data in the column can anyone tell me how to fix this problem and have the script access my database to display the table...
5
1466
by: eric dexter | last post by:
I am just trying to acess a function in wordgrid (savefile) to a button that is defined in TestFrame. I can't seem to make it work I either get an error that my variable isn't global or it makes other complaints. thanks in advance.. sorry for the simple question.. import wx import wx.grid as gridlib import sys
43
2092
by: Tony | last post by:
I'm working with GUI messaging and note that MFC encapsulates the message loop inside of a C++ class member function. Is this somehow inherently less robust than calling the message loop functions within main? (It just doesn't "feel" right to me). Example 1: class MyProg { public:
53
4757
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating records that have a '99' in them (it is similar to a CSV file). Some of my concerns are:
0
1009
by: vilas patil | last post by:
How I Can Add Alternate Color To The Rows Of Dbgrid
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.