closerwalk Posted June 25, 2007 Share Posted June 25, 2007 Below is some code that pulls all the projects from the database and orders them by the issued to project manager. It breaks each page after 53 rows. What I want to do is page-break when the project manager name changes. Any suggestions? Help examples.. etc.. [code<html> <head> <title>Projects By Project Manger</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <style type="text/css" media="print"> <!-- style { font-size: x-small; } td { font-size: xx-small; } th { font-size: xx-small; background-color: #333333; } --> </style> <body bgcolor="#CCCCCC"> <?php echo '<link rel="stylesheet" type="text/css" href="./zengarden-sample.css" media="screen" />'; // Make the connection then chech for the state of the connection if the state /// of the connection is dead it will report the error. $link = @mysql_connect('xxx', 'rxxx', 'xxx'); if (!$link) { die('Could not connect to MySQL server: ' . mysql_error()); } $dbname = 'project'; $db_selected = mysql_select_db($dbname, $link); if (!$db_selected) { die("Could not set $dbname: " . mysql_error()); } //Connection String Above This Line........................ $header_display_block .='<table width="100%" bgcolor="white"> <!--DWLayoutTable--><tr> <td width="182" height="40" valign="top"><font size="1">PRESCOTT COMMUNICATIONS, INC. CABLE ENGINEERING SERVICES</font></td><td width="376" valign="top"><div align="center"> <strong>PROJECT LIST</strong></div></td><td width="170" valign="top"><font size="1">REPORT DATE: </font> <font size="1">'.date("M d Y").'</font> </td></tr></table>'; /////////////////////// $number_rows = 53; $query = 'SELECT `PROJECT_NO` , `DATE_RECEIVED` , `PROJECT_NAME`,`BILLING_COMPL`, `issued_to` FROM project WHERE (`CUSTOMER_NAME` LIKE "%") AND (`Issued_to` LIKE "%") AND `CURRENT_PROJECT` = "Y" ORDER BY ISSUED_TO, PROJECT_NO, DATE_RECEIVED'; $result = mysql_query($query); $table_header .= $header_display_block; $table .=$table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $header_block .='<tr><th>Project No.</th><th>Issued To:</th><th>Project Name</th><th>Billing Compl.</th></tr>'; $table .= $header_block; while ($row = mysql_fetch_array($result)) { $date_received = str_replace( '-', '/' ,$row['DATE_RECEIVED']); $date_received = date("M d, Y", strtotime($date_received)); $table .= '<tr>'; $table .='<font size="1"><td nowrap>'.$row['PROJECT_NO'].'</td><td nowrap>'.$row['issued_to'].'</td><td width="600">'.$row['PROJECT_NAME'].'</td><td nowrap>'.$row['BILLING_COMPL'].' </td></font>'; $table.= '</tr>'; if($k>=$number_rows) { $table.= '</table>'; $table .= '</div>'; $table.= $table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $table .= $header_block; $k=0; } $k++; } echo $table; echo "</table>"; echo "</div>"; ?> </body> </html> </body> </html> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 25, 2007 Share Posted June 25, 2007 Store the project manager name in a variable and check it against each project manager name in the current row. If it's different, page break and reset the variable to the new name. Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 25, 2007 Author Share Posted June 25, 2007 Can you give me an example? Do you mean something like this: <code>if(!$project_mgr == $project_mgr) { $table.= '</table>'; $table .= '</div>'; $table.= $table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $table .= $header_block; } </code> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 25, 2007 Share Posted June 25, 2007 simple example: $result = mysql_query($query); $row = mysql_fetch_assoc($result); $proj_man = $row['project_manager']; do { if ($proj_man != $row['project_manager']) { $proj_man = $row['project_manager']; // page break here } // the rest of the loop here } while ($row = mysql_fetch_assoc($result)); Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 25, 2007 Author Share Posted June 25, 2007 I am sure I have got something wrong but its not working yet. <html> <head> <title>Projects By Project Manger</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <style type="text/css" media="print"> <!-- style { font-size: x-small; } td { font-size: xx-small; } th { font-size: xx-small; background-color: #333333; } --> </style> <body bgcolor="#CCCCCC"> <?php echo '<link rel="stylesheet" type="text/css" href="./zengarden-sample.css" media="screen" />'; // Make the connection then chech for the state of the connection if the state /// of the connection is dead it will report the error. $link = @mysql_connect(); if (!$link) { die('Could not connect to MySQL server: ' . mysql_error()); } $dbname = 'project'; $db_selected = mysql_select_db($dbname, $link); if (!$db_selected) { die("Could not set $dbname: " . mysql_error()); } //Connection String Above This Line........................ $header_display_block .='<table width="100%" bgcolor="white"> <!--DWLayoutTable--><tr> <td width="182" height="40" valign="top"><font size="1">PRESCOTT COMMUNICATIONS, INC. CABLE ENGINEERING SERVICES</font></td><td width="376" valign="top"><div align="center"> <strong>PROJECT LIST</strong></div></td><td width="170" valign="top"><font size="1">REPORT DATE: </font> <font size="1">'.date("M d Y").'</font> </td></tr></table>'; /////////////////////// $number_rows = 53; $query = 'SELECT `PROJECT_NO` , `DATE_RECEIVED` , `PROJECT_NAME`,`BILLING_COMPL`, `issued_to` FROM project WHERE (`CUSTOMER_NAME` LIKE "%") AND (`Issued_to` LIKE "%") AND `CURRENT_PROJECT` = "Y" ORDER BY ISSUED_TO, PROJECT_NO, DATE_RECEIVED'; $result = mysql_query($query); $table_header .= $header_display_block; $table .=$table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $header_block .='<tr><th>Project No.</th><th>Issued To:</th><th>Project Name</th><th>Billing Compl.</th></tr>'; $table .= $header_block; while ($row = mysql_fetch_array($result)) { $date_received = str_replace( '-', '/' ,$row['DATE_RECEIVED']); $date_received = date("M d, Y", strtotime($date_received)); $table .= '<tr>'; $table .='<font size="1"><td nowrap>'.$row['PROJECT_NO'].'</td><td nowrap>'.$row['issued_to'].'</td><td width="600">'.$row['PROJECT_NAME'].'</td><td nowrap>'.$row['BILLING_COMPL'].' </td></font>'; $table.= '</tr>'; $project_mgr = $row['issued_to']; if($k>=$number_rows) { $table.= '</table>'; $table .= '</div>'; $table.= $table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $table .= $header_block; $k=0; } $k++; } $query = 'SELECT `PROJECT_NO` , `DATE_RECEIVED` , `PROJECT_NAME`,`BILLING_COMPL`, `issued_to` FROM project WHERE (`CUSTOMER_NAME` LIKE "%") AND (`Issued_to` LIKE "%") AND `CURRENT_PROJECT` = "Y" ORDER BY ISSUED_TO, PROJECT_NO, DATE_RECEIVED'; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $proj_man = $row['issued_to']; do { if ($proj_man != $row['issued_to']) { $proj_man = $row['issued_to']; $table.= '</table>'; $table .= '</div>'; $table.= $table_header; $table .= '<div style="page-break-after:always">'; $table .='<table border="1" width="100%" bgcolor="white">'; $table .= $header_block; } // the rest of the loop here } while ($row = mysql_fetch_assoc($result)); echo $table; echo "</table>"; echo "</div>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 25, 2007 Share Posted June 25, 2007 I should have done it like this: <?php $result = mysql_query($query); $proj_man = ''; while ($row = mysql_fetch_assoc($result)) { if ($proj_man != $row['project_manager']) { $proj_man = $row['project_manager']; // page break here } // the rest of the loop here } ?> Anyway, what isn't working? Are you getting any errors? Are you getting results, but not what you expect, if so what are you getting and what do you expect? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.