Jump to content

DB Query for each service in clientareaproducts.tpl


SeanP

Recommended Posts

I was trying to convert some PHP I have in {php} tags in templates to hooks.  However, I need do a DB query for each service in the clientareaproducts.tpl within the following for loop:

{foreach key=num item=service from=$services}

How to I query each service, then use the template variables in the template?  I am fine with keeping the {php} tag in the template for this (I am the designer and developer of my site), but I get an error trying to use PDO in the {php} tags ("ParseError: syntax error, unexpected 'use' (T_USE)":

use WHMCS\Database\Capsule;

// Get PDO for the database queries
$pdo = Capsule::connection()->getPdo();

How to I either use PDO in the {php} tag or move this to a hook and still be able to do a DB query for each service?
 

Link to comment
Share on other sites

14 hours ago, SeanP said:

How to I query each service, then use the template variables in the template? 

perhaps the hook in the thread below will give you a starting point - it loops through the $services array; queries the database for a dedicated IP value; adds it back to the array and returns the updated array back to the template.

14 hours ago, SeanP said:

I am fine with keeping the {php} tag in the template for this

don't be - at some point, it really will be deprecated and if your php knowledge is good enough for use in tags, it should be good enough for hooks.

... and depending on what you're wanting to do, you might not even need to use capsule to query the database.... you might be able to get the info using the class docs or from other existing template variables.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated