473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template with alternating currentblock entries

i am using templates via HTML_Template_I T to create a table from the
results of a mysql query. i wanted to change the background image of
alternating rows in the table. i thought i could do this by defining
two different blocks in the template file and setting the current block
based on ( $thisRowNum % 2 ).

when the final table is displayed, all the "even" rows are displayed
before all the "odd" rows. in other words, the rows are not
interleaved. how can i get the rows to display properly alternating?

--------------------------
my template file 'searchResults. html' contains:

<table width="100%" border="0" cellpadding="0" cellspacing="5" >
<!-- BEGIN ENTRY_EVEN -->
<tr><td rowspan="3">{AU THOR}</td></tr>
<!-- END ENTRY_EVEN -->

<!-- BEGIN ENTRY_ODD -->
<tr><td rowspan="3" class="shadeDar ker2">{AUTHOR}</td></tr>
<!-- END ENTRY_ODD -->
</table>

--------------------------
my PHP code in 'searchAction.p hp' contains:

$template = new HTML_Template_I T( "./templates" );
$template->loadTemplatefi le( "searchResult.h tml", true, true );

$thisRowNum = -1;
while ( $row = mysql_fetch_arr ay( $result )) {
$thisRowNum++;
if ( $thisRowNum % 2 ) {
$currBlock = "ENTRY_ODD" ;
} else {
$currBlock = "ENTRY_EVEN ";
}
print "thisRowNum = $thisRowNum; currBlock = $currBlock; author
{$row["author"]}<< <br>\n";


$template->setCurrentBloc k( $currBlock );
$template->setVariable( "AUTHOR", $row["author"] );
$template->parseCurrentBl ock();
} // end while mysql_fetch_arr ay

$template->parse();
$template->show();

--------------------------
which produces this output:

thisRowNum = 0; currBlock = ENTRY_EVEN; author >>Boff, Leonardo<<
thisRowNum = 1; currBlock = ENTRY_ODD; author >>Galilea, Segundo<<
thisRowNum = 2; currBlock = ENTRY_EVEN; author >>Manning, Brennan<<
thisRowNum = 3; currBlock = ENTRY_ODD; author >>Nolan, Albert<<
thisRowNum = 4; currBlock = ENTRY_EVEN; author >>Segundo, Juan Luis<<

--------------------------
but the table is shown with the authors in the following order:

(ENTRY_EVEN) Boff, Leonardo
(ENTRY_EVEN) Manning, Brennan
(ENTRY_EVEN) Segundo, Juan Luis
(ENTRY_ODD) Galilea, Segundo
(ENTRY_ODD) Nolan, Albert

is there some buffer-flushing issue here?

thanks - bettyann

Jul 17 '05 #1
2 1739
<be******@campb ell.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
i am using templates via HTML_Template_I T to create a table from the
results of a mysql query. i wanted to change the background image of
alternating rows in the table. i thought i could do this by defining
two different blocks in the template file and setting the current block
based on ( $thisRowNum % 2 ).


for what is worth here is an example how it is done in TT:

http://www.templatetamer.org/index.p...ingListExample

rush
--
http://www.templatetamer.com/
http://www.folderscavenger.com/
Jul 17 '05 #2
rush wrote:
for what is worth here is an example how it is done in TT:
http://www.templatetamer.org/index.p...ingListExample


thanks, rush, for pointing me in the right direction. i needed to nest
both blocks in a "super-block". then, after selecting and parsing each
block, i had to select and parse the "super-block". this makes sense
since all blocks group together -- all the "super-blocks" group
together regardless of the "sub-blocks" they contain. this allows my
alternating rows.

--------------------------
my template file 'searchResults. html' contains:

<table width="100%" border="0" cellpadding="0" cellspacing="5" >
<!-- BEGIN ENTRY -->
<!-- BEGIN ENTRY_EVEN -->
<tr><td>{AUTHOR }</td></tr>
<!-- END ENTRY_EVEN -->

<!-- BEGIN ENTRY_ODD -->
<tr><td class="shadeDar ker2">{AUTHOR}</td></tr>
<!-- END ENTRY_ODD -->
<!-- END ENTRY -->
</table>

--------------------------
my PHP code in 'searchAction.p hp' contains:

$template = new HTML_Template_I T( "./templates" );
$template->loadTemplatefi le( "searchResult.h tml", true, true );

$thisRowNum = -1;
while ( $row = mysql_fetch_arr ay( $result )) {
$thisRowNum++;
if ( $thisRowNum % 2 ) {
$currBlock = "ENTRY_ODD" ;
} else {
$currBlock = "ENTRY_EVEN ";
}

// set current block to "ENTRY_EVEN " or "ENTRY_ODD"
$template->setCurrentBloc k( $currBlock );
$template->setVariable( "AUTHOR", $row["author"] );
$template->parseCurrentBl ock();

// set current block to 'super-block' "ENTRY"
$template->setCurrentBloc k( "ENTRY" );
$template->parseCurrentBl ock();

} // end while mysql_fetch_arr ay

$template->parse();
$template->show();

thanks for the help - bettyann

Jul 17 '05 #3

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

Similar topics

1
1394
by: Ralph Snart | last post by:
i'm trying to do the classic alternating table row colors trick. i can't use position() mod 2 in this case because sometimes the template is called but it decides not to print the particular element. i really need to keep track of how many times it has printed something, but since you can't modify variables in xslt, i have no idea how to do it. the fragment looks something like this: <xsl:template match="story">
8
2458
by: Colin Mc Mahon | last post by:
Hi all, I am currently using a system you are probably familiar with if you have done any templating with vbscript, define a template file with special tokens in it(like ##Content## etc), load the file and replace these with strings on each page. This works well but means on some pages there are vast string concatenations to make up the content areas etc. I had a bit of a brainwave and started rewriting my templating functions to...
3
4433
by: mahsa | last post by:
Hi,How can I access to checkbox control in footer template of datalist and fire the selectedchangeindex event? -- Regards mahsa
1
4669
by: Eirik Eldorsen | last post by:
I'm trying to set alternating bgcolor for a datalist with 2 columns. My problem is that its the alternating cell that get the bgcolor, not the row. Is it possible to set alternating color of rows? Here is my code: <asp:DataList id=dlKommuner runat="server" Width="400px" RepeatColumns="2" CellPadding="3"> <AlternatingItemStyle Width="200px" CssClass="arow"> </AlternatingItemStyle>
3
1846
by: Andy Fish | last post by:
Hi, Say I had a repeater-like situation but were I wanted to have every 3rd item look different instead of every alternating one. I could write my own custom control and in the ASPX file something like this: <myControl> <mainItemTemplate>...</> <secondItemTemplate>...</> <thirdItemTemplate>...</>
9
2686
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to perform updates. All the styles that are set are being followed by all templated columns with the exception for the update column. The update column does set the BackColor appropriately but when setting its ForeColor the LinkButton's color is blue and...
3
3700
by: Daniel Manes | last post by:
My DataGridView is set up like this: * Main row background color = white * Alternating row background color = light gray I also have a read-only (non-editable) column I want to show up as solid dark gray (i.e., no alternating row colors), but it shows up as alternating dark/light gray. Is there any way to get around this?
4
5684
by: mike | last post by:
how can I change the font color for an alternating row where the column data is formatted as a link? setting a style in the stylesheet for a { color:white; }
5
3004
by: prakash.mirji | last post by:
I am using evaluation copy of RW 9.0 for porting one of C++ application on RHEL4 (x86 platform). We are getting some issues into RW template classes. Please need assistance on this issue. Here is the problem: Application is using below mentioned template class which is declared at static in Engine.h
0
8242
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
8177
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
8681
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
8629
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...
0
8488
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
7170
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...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
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...
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.