close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Print style for repeating regions

Thread began 3/23/2009 6:07 pm by troyd | Last modified 3/29/2009 12:23 am by troyd | 4786 views | 8 replies |

troyd

Print style for repeating regions

I am having trouble figuring out how to print out a results page of records without cutting off parts of some records.
These records are formatted to be in a box with an outline.

My goal is to actually tell the printer to print 2 records per page and then go on to the next page. I've tried using a print style sheet, but that's not working for me.

I have also tried using a div page break, but since the page of records is dynamically generated, I can not figure out where that would go.

Is there some clever way I can use the something with alternate styles here since I am looking at doing 2 records per page?

If this is a CSS issue only, I will move on to that forum but I wanted to start here.

Thanks,
Troy

Sign in to reply to this post

Danilo Celic

By "using a div page break" that you mean that you're using one of the the CSS page break styles. If so, then you can write out that div every other row. How to do that would depend on the specific server language you're using, but basically you create a counter variable, and then increment that variable each time through the repeating region. You'd then test that variable to see if it is a multiple of two. Assuming that you start your counter at 1 , then you can use the modulus operator (determines the remainder of division of two number as in 3 divided by 2 has a remainder of 1) to see if there is a need to output your page break div.

A simple off the cuff example in PHP:
<?php
$rowCounter = 1;
?>
<?php
// start repeat region code

?>
Content to display
<?php
if( ($rowCounter % 2) == 0 ){
// write out page break div
}


$rowCounter++; // increment counter
// end repeat region code
?>

Sign in to reply to this post

troyd

That's exactly what I was looking for. Thanks!

I am doing this in PHP. The div page break I was trying is <div style="page-break-after:always"></div>

I'm headed to DW right now to try this out. Not sure if I totally understand what to do, but hopefully I can figure it out. I'll let you know either way.

Thanks again,
Troy

Sign in to reply to this post

troyd

Ok, I was too optomistic I guess.

The page that I am trying to apply this to is part of a DataAssist wizard creation that I have heavily altered over the past few weeks. So I am having trouble making sense of the counter.
I wasn't sure if it was ok to copy and paste my code here so I am just including the comments to show what type of counter I have.

// RepeatSelectionCounter_1 Begin Loop

// RepeatSelectionCounter_1 Begin Alternate Content

// RepeatSelectionCounter_1 End Alternate Content

// RepeatSelectionCounter_1 End Loop

Is this the same as what you are referring to as the row counters? I might have created this incorrectly. Where is the menu item for creating the row counter variable?

Thanks,
Troy

Sign in to reply to this post

troyd

Would it be more helpful for me to post my code here?

Troy

Sign in to reply to this post

Danilo Celic

Sorry, Troy, I didn't see your replies.

There is no menu item for creating a row counter variable, you have to enter that code in yourself.

I think that by default DataAssist creates the multiply repeated regions (left to right, then down to the next row), so adding a page break div within a table cell may cause the layout to display weirdly.

It might be better to create a separate printable page and then write out each item in a div and then add the page break div every other row from the recordset.

Sign in to reply to this post

troyd

Oh, you totally lost me now. I'm comfortable with divs and CSS, but not sure how to create a repeating div region.

Can you point me in the direction of some reading on the subject of both the row counter variable and the use of divs instead of tables for recordsets? I prefer divs anyway, but didn't realize it was an option.

Thanks,
Troy

Sign in to reply to this post

Danilo Celic

You can create a repeating div region within Dreamweaver pretty much the same way you create a repeating row region in a table, first you add the content you want to repeat, a div in this case, then select that content, again, the div and add repeat region to the selection by going to the Server Behaviors panel, clicking the + button and selecting Repeat Region.

When it comes to counter, I've already supplied some sample code, but I'll try to explain again...basically, you create a variable, set it's starting value, in this case 1, but it could be any value that is useful for the case at hand, and then within the repeat region, you increment that variable value (add one to the current value).

If you need to do something with the value as you loop (repeat), then check that value, either before the increment or after the increment, depending on exactly what you want to accomplish. In this case it checks the remainder of the division of the counter by 2, if that remainder is 0, then we have an even row, then you can do whatever you want to based upon the result of the check against the current value of the counter, in this case write out the page break div, but you can do other things, such as write out a CSS class name for the alternate rows.

You can read up on how to apply repeat regions in the "Making pages dynamic" section of the Dreamweaver help. As for counter variables, I'm not aware of anything in particular that discusses the topic. A casual search of Google for PHP counter variable yeilds a few results, perhaps start there.

Sign in to reply to this post

troyd

That did it! Thanks a lot.:D
It took me about 6 hours today to get through all the mistakes I was making. Kept putting the 3 parts of your code in the wrong place. I read lots of stuff online about alternating row colors and that helped a little. There are lots of ways to do the same thing I think.

It took me forever to finally realize I had to echo the div.
I have your code here in use and it is giving me a desired page break every 2 records.

I will paste my practice code here for any critique. Please let me know if you see anything out of place or unnecessary. Such as the use of } else { .

It was working either way.

using

if( ($rowCounter % 2) == 0 ){
// write out page break div
echo '<div style="page-break-after:always"></div>';
} else {
echo '<div style="page-break-after:avoid"></div>';
}

or just

if( ($rowCounter % 2) == 0 ){
// write out page break div
echo '<div style="page-break-after:always"></div>';
}

but I figured it wouldn't hurt to use the "page-break-after:avoid" too.

One area that puzzles me is that even without using a @media print in the style, it still gives the page break only when printed. (Which is what I want). But just for future reference, I tried to also give it a background color every other row and that didn't work. It ignored my color but the page break still works. And I guess you can't use a media type in an inline style?

Here is my test code. It repeats all my records and when printed, it gives me a dynamically generated page break after every 2 records.

<?php
$rowCounter = 1;
?>
<?php do { ?>
<div><?php echo $row_Recordset1['id']; ?></div>
<?php
if( ($rowCounter % 2) == 0 ){

echo '<div style="page-break-after:always"></div>';
} else {
echo '<div style="page-break-after:avoid"></div>';
}
$rowCounter++;

?>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
<?php
mysql_free_result($Recordset1);
?>

Now to put into my working pages... :o

TroyD

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...