This topic is locked

Printing master and details records together

12/9/2014 5:02:02 PM
PHPRunner Tips and Tricks
Sergey Kornilov admin

Lets see how we can print orders and order details info together on the same page. This will required a bit of custom coding.
[size="4"]1. Modify SQL Query or Master table[/size]
Modify SQL query of Orders table adding a dummy field:

SELECT

OrderID,

OrderID as OrderID2,

CustomerID

...

from Orders


OrderID2 is our new field. Do not add it to any page yet, we'll do it manually.
[size="4"]2. Changes in Visual Editor[/size]

  • proceed to printer-friendly page, turn on borders display and add a new table row after the existing row with fields.
  • merge cells of that new row together
  • via 'Insert field' toolbar button insert new OrderID2 field into that large cell
  • double-click on this field and set 'View as' type to 'Custom.
    This is how it supposed to look:


[size="4"]3. 'View as' Custom code[/size]
Here is the code to add to 'View as' Custom code window. This code retrieves corresponding Order Details info for the current record. Modify it accordingly.

global $dal;

$tblOrders = $dal->Table("Order Details");

$rs = $tblOrders->Query("OrderID=".$data["OrderID"],"");

$value="<div id='mytable'><table><tr><th>Product</th><th>Price</th><th>Quantity</th></tr>";

while($data2=db_fetch_array($rs))

{

$value.="<tr><td>".$data2['ProductID']."</td><td>".$data2['UnitPrice'].

"</td><td>".$data2['Quantity']."</td></tr>";

}
$value.="</table></div>";


[size="4"]4. Custom CSS[/size]
To make child records table look better add the following to the 'Custom CSS' section of Style Editor.

#mytable table {

border: 1px solid #c0c0c0;

}

#mytable td,th {

padding: 7px;

}

#mytable th {

background: #e0e0e0;

}


[size="4"]5. Generated application is supposed to look like this:[/size]

G
GregJ 12/9/2014

IT WORKS!!! Great tutorial, thanks for taking the time to do this Sergey.
One final tweak. How can I insert a page break so that each Master / Detail set prints out on separate page instead of one long report?