{"id":3882,"date":"2023-09-21T14:01:48","date_gmt":"2023-09-21T13:01:48","guid":{"rendered":"https:\/\/help.expertsender.com\/?post_type=es&#038;p=3882"},"modified":"2024-03-19T13:25:09","modified_gmt":"2024-03-19T12:25:09","slug":"getrowsbytemplate","status":"publish","type":"es","link":"https:\/\/help.expertsender.com\/pl\/emp\/dynamic-content\/data-tables\/getrowsbytemplate\/","title":{"rendered":"GetRowsByTemplate"},"content":{"rendered":"\n<p><code>GetRowsByTemplate<\/code> method retrieves a number of rows returned by SQL query template. To use a template, it needs to be defined in ExpertSender web panel first. Template can be any valid SQL query that returns rows (<code>SELECT<\/code> query). It is possible to create templates with parameters.<\/p>\n\n\n\n<p><strong>1. Method signature<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"rows = GetRowsByTemplate(template, parameters)\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #BABED8\">rows <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">GetRowsByTemplate<\/span><span style=\"color: #BABED8\">(template<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> parameters)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Parameter definition<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Name<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>template<\/td><td>string<\/td><td>Required. Template name.<\/td><\/tr><tr><td>parameters<\/td><td>array of Param objects<\/td><td>Optional. Array of objects defining template parameters. Can be omitted if template has no parameters.<\/td><\/tr><tr><td>rows<\/td><td>array of rows<\/td><td>Return value. Array of rows. Every row itself is an array of key-value pairs (column name =&gt; column value). Column name is string. Column value type depends on actual type in the database. Array is empty if no data was found.<br>Rows table can be enumerated upon, e.g. to display in form of HTML table. See examples for more information.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><code>Param<\/code> object parameter definition<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Name<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>Name<\/td><td>string<\/td><td>Parameter name.<\/td><\/tr><tr><td>Value<\/td><td>object<\/td><td>Parameter value. Value type depends on defined parameter type.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>NOTE: typically, <code>Param<\/code> objects are created using constructor, which is more convenient. See examples for more information.<\/p>\n\n\n\n<p><strong>2. Using GetRowsByTemplate method<\/strong><\/p>\n\n\n\n<p>Example &#8211; simple request using template with two parameters:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#babed8;--cbp-line-number-width:7.703125px;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"GetRowsByTemplate('MyTemplate', new [] {new Param('numberParam', 123), new Param('textParam', 'abc')})\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg  style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-palenight\" style=\"background-color: #292D3E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #82AAFF\">GetRowsByTemplate<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">MyTemplate<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">new<\/span><span style=\"color: #BABED8\"> [] <\/span><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\">new <\/span><span style=\"color: #F07178\">Param<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">numberParam<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> 123<\/span><span style=\"color: #89DDFF\">),<\/span><span style=\"color: #BABED8\"> new <\/span><span style=\"color: #F07178\">Param<\/span><span style=\"color: #89DDFF\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">textParam<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">abc<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">)}<\/span><span style=\"color: #BABED8\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Returned output is the same as with regular GetRows method. You may enumerate rows, access rows and columns by indexes etc. Please see<a href=\"https:\/\/sites.google.com\/expertsender.com\/dynamic-content-documentation\/data-tables\/getrows\"> GetRows documentation<\/a> for more details.<\/p>\n","protected":false},"author":6,"featured_media":0,"parent":3874,"menu_order":214,"template":"","format":"standard","emp-category":[],"class_list":["post-3882","es","type-es","status-publish","format-standard","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es"}],"about":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/types\/es"}],"author":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/users\/6"}],"version-history":[{"count":2,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3882\/revisions"}],"predecessor-version":[{"id":8867,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3882\/revisions\/8867"}],"up":[{"embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/es\/3874"}],"wp:attachment":[{"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/media?parent=3882"}],"wp:term":[{"taxonomy":"emp-category","embeddable":true,"href":"https:\/\/help.expertsender.com\/pl\/wp-json\/wp\/v2\/emp-category?post=3882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}