Have you ever wanted to add the Previous and Next navigation links in the Master/Details pages of web applications that generated by PHPMaker? As we have already known, PHPMaker can generate the Master/Detail pages powerfully only in a few seconds. Unfortunately, it has not provided the navigation links as well as the pagination links in the List pages in order to go or browse to the next or previous records/page quickly.
In this article, I will show you how you can add the navigation links in a Master/Detail page easily and quickly. We will add the code from Server Events of PHPMaker. In other words, you don't have to customize the generated scripts for this. This navigation links is very useful for your users, so they don't have to go back to its Master page each time they want to go to the next or previous Master/Detail records.
In this example, I am using the following tables for the Master/Details relationships:
- products (master) -> orders (detail)
- orders (master) -> order_details (detail)
- products (master) -> components (detail)
As a result, I also just created a video for you. Please note that this following video below is related to this article that I wrote a few days ago. In other words, make sure you have already had the related files and follow all steps in that article before implementing the solution in this article.
Updated on February 10, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
[hidepost]
- Double click your orders.pmp file, and it should call PHPMaker to run it.
-
Now let's add the navigation links in the orderslist.php page. To do this, click on orders table in the database (left) pane, and then click on Code (Server Events, Client Scripts and Custom Templates) tab. Expand this location: Server Events -> Table-Specific -> List Page -> Page_DataRendering, and then insert the following code into the Page_DataRendering function:
if (@$_GET["showmaster"]=="products" && isset($_GET["Id"])) { $maxID = ew_ExecuteScalar("SELECT MAX(Id) FROM products"); $minID = ew_ExecuteScalar("SELECT MIN(Id) FROM products"); $curID = intval($_GET["Id"]); if ($curID < $maxID) { $nextID = $curID + 1; } else { $nextID = $minID; } if ($curID > $minID) { $prevID = intval($_GET["Id"]) - 1; } else { $prevID = $maxID; } $header = "<a href='orderslist.php?showmaster=products&Id=".$prevID."' title='Product ".$prevID."'>Prev</a>"; $header .= " | <a href='orderslist.php?showmaster=products&Id=".$nextID."' title='Product ".$nextID."'>Next</a>"; } -
Next step, let's add again the navigation links in the order_detailslist.php page. To do this, click on order_details table in the database (left) pane, and then click on Code (Server Events, Client Scripts and Custom Templates) tab. Expand this location: Server Events -> Table-Specific -> List Page -> Page_DataRendering, and then insert the following code into the Page_DataRendering function:
if (@$_GET["showmaster"]=="orders" && isset($_GET["Id"])) { $maxID = ew_ExecuteScalar("SELECT MAX(Id) FROM orders"); $minID = ew_ExecuteScalar("SELECT MIN(Id) FROM orders"); $curID = intval($_GET["Id"]); if ($curID < $maxID) { $nextID = $curID + 1; } else { $nextID = $minID; } if ($curID > $minID) { $prevID = intval($_GET["Id"]) - 1; } else { $prevID = $maxID; } $header = "<a href='order_detailslist.php?showmaster=orders&Id=".$prevID."' title='Order ".$prevID."'>Prev</a>"; $header .= " | <a href='order_detailslist.php?showmaster=orders&Id=".$nextID."' title='Order ".$nextID."'>Next</a>"; } -
Next step, let's add again the navigation links in the componentslist.php page. To do this, click on components table in the database (left) pane, and then click on Code (Server Events, Client Scripts and Custom Templates) tab. Expand this location: Server Events -> Table-Specific -> List Page -> Page_DataRendering, and then insert the following code into the Page_DataRendering function:
if (@$_GET["showmaster"]=="products" && isset($_GET["Id"])) { $maxID = ew_ExecuteScalar("SELECT MAX(Id) FROM products"); $minID = ew_ExecuteScalar("SELECT MIN(Id) FROM products"); $curID = intval($_GET["Id"]); if ($curID < $maxID) { $nextID = $curID + 1; } else { $nextID = $minID; } if ($curID > $minID) { $prevID = intval($_GET["Id"]) - 1; } else { $prevID = $maxID; } $header = "<a href='componentslist.php?showmaster=products&Id=".$prevID."' title='Product ".$prevID."'>Prev</a>"; $header .= " | <a href='componentslist.php?showmaster=products&Id=".$nextID."' title='Product ".$nextID."'>Next</a>"; } - Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.