I thought this would have been easy, but noooooo!
Here’s the basic setup: a single weblog, custom fields of project_client, project_name, project_priority, project_duedate, project_comments, and project_notes.
I have to display a page of tables, one for each distinct client. The table shows ongoing projects. Each project uses two rows: project name, priority, due date, and comments. The next rows displays the notes field, spanning 4 columns.
One of the conditions of the setup is that it be as easy as possible for my client—in other words, he can’t set up new weblogs, etc. He can enter new clients as members, though, and change the custom project_client dropdown field to add each new client.
So far, so good. Here’s how I did it (this is the repeating section of the page). PHP on, parse on output:
<div id="projectdiv">
{exp:query sql="SELECT username, screen_name as company FROM exp_members WHERE group_id = '6' ORDER BY screen_name" }
<table class="projects" width="670" border="0" cellpadding="0" cellspacing="0">
<caption align="top">{company} Project Report</caption>
<tr class="tablehead">
<td width="160" class="name">Name</td>
<td width="100"><div align="center">Priority</div></td>
<td width="110"><div align="center">Due Date </div></td>
<td width="300"><div align="center">Comments</div></td>
</tr>
<?php $rowcolor = " odd"; ?>
{exp:weblog:entries weblog="projects"}
{if project_client == username}
<tr valign="top" class="entry<?php echo $rowcolor; ?>">
<td class="name">{title}</td>
<td class="priority">{project_priority}</td>
<td class="duedate">{project_duedate format="%m/%d/%Y"}</td>
<td class="comments">{project_comments}</td>
</tr>
<tr class="notes<?php echo $rowcolor; ?>">
<td colspan="4">Notes: {project_notes}</td>
</tr>
<?php $rowcolor = ($rowcolor == "") ? " odd" : ""; ?>
{/if}
{/exp:weblog:entries}
</table>
{/exp:query}
</div>All fine and dandy, except for the alternating row colors. According to MY logic, the rowcolor switch should ONLY happen when the {if project_client==username} block is done. But it doesn’t work that way, it seems. Even if nothing (the two table rows) is output, the $rowcolor switch still executes. Because this code loops through all the entries, there may be 2 entries skipped, maybe 3, maybe 5, no telling. Each skip changes $rowcolor, so that only by chance do my row colors alternate.
I’m open to any suggestions as to how to improve this, or redo it, or whatever. I just need to get it working soonly.