Jump to content


Photo

Do Something Every x Records


  • Please log in to reply
2 replies to this topic

#1 benhodgson

benhodgson
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationLeicester, UK

Posted 07 September 2006 - 11:05 AM

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

$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++;
}

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.

#2 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 07 September 2006 - 11:33 PM

Use something like
if($i % 8 == 0){//show spacer image or whatever}

That should separate them.

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 08 September 2006 - 12:32 AM

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
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users