Jump to content

Simple Query and adding variable in Smarty example?


gamestuff

Recommended Posts

Hey there,

 

I hate to have to ask here, but after much trial and error I just am not getting this new query system and I really find a huge lack of examples so far so I am asking for help.

 

Basically what I want to do is simple:

 

I have a field called "Slot_Number" in the 'tblhosting' table, which I need to display on the Product Details page. This query will need to search for the current $serviceid, and based on that $serviceid pull the "slot_number" value and pass it as a variable I can display/play with.

 

In Mysql I would do something like this:

 

SELECT  `slot_number` 
FROM  `tblhosting` 
WHERE  `id` =  $serviceid

 

 

How do I go about selecting a value from a query in this new system and then passing it as a variable to be used?

 

Thanks!

Link to comment
Share on other sites

Thanks for the direction,

 

So my understanding is I need to put this into a hook file?

 

I have taken your php and put it into a file called showSlot.php

 

<?php 

use Illuminate\Database\Capsule\Manager as Capsule;

function hook_showSlot($vars){
$selectSlotNum = Capsule::table("tblhosting")->where("id", "=", $serviceid)->get();

echo $selectSlotNum[0]->slot_number;  
}

add_hook("ClientAreaProductDetails", 1, "hook_showSlot");

 

 

How do I now call the slot number to display on the page clientareaproductdetails.tpl?

 

Also, is the hook called before or after the page is loaded? I'm using the $serviceid variable based on the variables available from the {debug} command on this particular page, but if the hook is loaded first it probably wouldn't have this variable accessible? I don't even know if this variable is accessible anyways.

Link to comment
Share on other sites

modify your actionhook function like below:

 

<?php  

use Illuminate\Database\Capsule\Manager as Capsule; 

function hook_showSlot($vars){ 
   $selectSlotNum = Capsule::table("tblhosting")->where("id", "=", $vars['serviceid'])->get(); 

   return array("slotnumber" => $selectSlotNum[0]->slot_number);
}
add_hook("ClientAreaPage", 1, "hook_showSlot");

 

- - - Updated - - -

 

modify your actionhook function like below:

 

<?php  

use Illuminate\Database\Capsule\Manager as Capsule; 

function hook_showSlot($vars){ 
   if ($vars['action']!=="productdetails"){
       return array();
   }
   $selectSlotNum = Capsule::table("tblhosting")->where("id", "=", $vars['serviceid'])->get(); 

   return array("slotnumber" => $selectSlotNum[0]->slot_number);
}
add_hook("ClientAreaPage", 1, "hook_showSlot");

 

then place this variable {$slotnumber} in /templates/your-template/clientareaproductdetails.tpl where you need it to be displayed

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