Jump to content

Archived

This topic is now archived and is closed to further replies.

benhodgson

Do Something Every x Records

Recommended Posts

I have the following piece of code, designed for the print-out of ID cards for a member system.

[code]
$query="SELECT * FROM memb WHERE id_printed='0'";
$result=mysql_query($query) or die("<strong>Error ".mysql_errno().":</strong><br> ".mysql_error()."<br><br>\nQuery: $query");

$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first_name");
$last=mysql_result($result,$i,"surname");
$exec_pos=mysql_result($result,$i,"exec_pos");
$day=mysql_result($result,$i,"joined_day");
$month=mysql_result($result,$i,"joined_month");
$year=mysql_result($result,$i,"joined_year");
$image=mysql_result($result,$i,"image");

if(empty($image)){
$image = "http://www.demonfm.co.uk/images/members/membphotos/nophoto.gif";
}

if (!($exec_pos=='') && !($exec_pos=='None') && !($exec_pos=='none'))
{
echo "
<div class=\"idmem\">
<div class=\"extimg\">
<img src=\"name.png\" alt=\"name\" />
</div>
<div class=\"fbg\">
<img src=\"fbg.png\" alt=\"fieldbg\" />
</div>
<div class=\"fname\">
<span class=\"text\">$first $last</span>
</div>
<div class=\"extimg\">
<img src=\"valid.png\" alt=\"validuntil\" />
</div>
<div class=\"fbg\">
<img src=\"fbg.png\" alt=\"fieldbg\" />
</div>
<div class=\"fjoin\">
<span class=\"text\">$day $month $year</span>
</div>
<div class=\"extimg\">
<img src=\"exec.png\" alt=\"execpos\" />
</div>
<div class=\"fbg\">
<img src=\"fbg.png\" alt=\"fieldbg\" />
</div>
<div class=\"fjoin\">
<span class=\"text\">$exec_pos</span>
</div>
<div class=\"exfid\">
<span class=\"id\">$id</span>
</div>
<div class=\"exfpic\">
<img src=\"$image\" width=\"99\" height=\"128\" alt=\"memberpic\" /><br />
<img class=\"logo\" src=\"logo.png\" alt=\"demonlogo\" />
</div>
</div>
";
}
else
{
echo "
<div class=\"idmem\">
<div class=\"timg\">
<img src=\"name.png\" alt=\"name\" />
</div>
<div class=\"fbg\">
<img src=\"fbg.png\" alt=\"fieldbg\" />
</div>
<div class=\"fname\">
<span class=\"text\">$first $last</span>
</div>
<div class=\"timg\">
<img src=\"valid.png\" alt=\"validuntil\" />
</div>
<div class=\"fbg\">
<img src=\"fbg.png\" alt=\"fieldbg\" />
</div>
<div class=\"fjoin\">
<span class=\"text\">$day $month $year</span>
</div>
<div class=\"fid\">
<span class=\"id\">$id</span>
</div>
<div class=\"fpic\">
<img src=\"$image\" width=\"99\" height=\"128\" alt=\"memberpic\" /><br />
<img class=\"logo\" src=\"logo.png\" alt=\"demonlogo\" />
</div>
</div>
";
}

$i++;
}
[/code]

8 cards will fit onto a single A4 sheet of paper. The problem is that the next two cards then span across two sheets, cutting them in half.

Is there any way to insert a blank space (Probably as an image or empty DIV) every 8 records to push the next two cards down to the next page and, based on the code above, what would be the easiest way to do this?

Thanks in advance.

Share this post


Link to post
Share on other sites
Use something like
if($i % 8 == 0){//show spacer image or whatever}

That should separate them.

Share this post


Link to post
Share on other sites
If I need precision printing I generate a PDF file instead of relying on a print of the html page.

see http://www.fpdf.org

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.