Jump to content

Custom mysql query


Gibby13

Recommended Posts

So I have Configurable addon for a few products.

It has values like

1000GB

2000GB

3000GB

 

ect...

 

 

I need to be able to query the mysql database and grab this value. I am OK in mysql, so I have been digging around in phphmyadmin, but I can not figure out how it stores this value for a service that a client has.

Link to comment
Share on other sites

Do you mean configurable options? Something like this should work. replace SERVICEID with the service ID from WHMCS, and OPTIONNAME with the name of the configurable option.

 

SELECT 
   pcos.optionname AS config_option_value
FROM 
   tblproductconfigoptionssub pcos,
   tblproductconfigoptions pco,
   tblhostingconfigoptions hco
WHERE 
   pcos.configid = pco.id AND
   hco.configid = pco.id AND
   hco.optionid = pcos.id AND
   pco.optionname = '[b]OPTIONNAME[/b]' AND
   hco.relid=[b]SERVICEID[/b]

Link to comment
Share on other sites

So you want the query to return the client ID, the service ID, and the config option values? Try this:

 

SELECT
 c.id AS userid, h.id AS serviceid, pcos.optionname AS config_option_value 
FROM 
 tblhosting h, tblclients c, tblproducts p, tblproductconfigoptionssub pcos, tblproductconfigoptions pco, tblhostingconfigoptions hco 
WHERE 
 pcos.configid = pco.id AND 
 hco.configid = pco.id AND 
 hco.optionid = pcos.id AND
 hco.relid = h.id AND 
 c.id = h.userid AND
 p.id = h.packageid AND
 p.gid = [b]PRODUCT_GROUP_ID[/b] AND
 pco.optionname = '[b]OPTIONNAME[/b]'

 

EDIT: It would probably be easier if you just explained what you were trying to accomplish.

Link to comment
Share on other sites

I am writing a bash script to do the following;

First it connects bandwidth monitoring server and pulls the BW metering,

then if a client has a Product that is in the Product Group VPS or Cluster, grab the value of the Bandwidth option and the appliance name

then the script will put the data together.

 

Once I have that done, I am going to convert it to a php script and hopefully be able to have clients see it when logged in

Link to comment
Share on other sites

So this is what I have so far that works:

 

SELECT
 c.id AS userid, h.id AS serviceid, pcos.optionname AS config_option_value, dedicatedip
FROM
 tblhosting h, tblclients c, tblproducts p, tblproductconfigoptionssub pcos, tblproductconfigoptions pco, tblhostingconfigoptions hco
WHERE
 pcos.configid = pco.id AND
 hco.configid = pco.id AND
 hco.optionid = pcos.id AND
 hco.relid = h.id AND
 c.id = h.userid AND
 p.id = h.packageid AND
 p.gid = 3 AND
 pco.optionname = 'Bandwidth

 

I try to add an OR like this but it doesn't work:

 

SELECT
 c.id AS userid, h.id AS serviceid, pcos.optionname AS config_option_value, dedicatedip
FROM
 tblhosting h, tblclients c, tblproducts p, tblproductconfigoptionssub pcos, tblproductconfigoptions pco, tblhostingconfigoptions hco
WHERE
 pcos.configid = pco.id AND
 hco.configid = pco.id AND
 hco.optionid = pcos.id AND
 hco.relid = h.id AND
 c.id = h.userid AND
 p.id = h.packageid AND
 p.gid = 3 OR
 p.gid = 4 AND
 pco.optionname = 'Bandwidth

 

 

Also my bash code looks like this

 

#!/bin/bash
DATA_TO_GATHER=`mysql -u xxxx --password='xxxxx' -D whmcs -e \
"SELECT
 c.id AS userid, h.id AS serviceid, pcos.optionname AS config_option_value, dedicatedip
FROM
 tblhosting h, tblclients c, tblproducts p, tblproductconfigoptionssub pcos, tblproductconfigoptions pco, tblhostingconfigoptions hco
WHERE
 pcos.configid = pco.id AND
 hco.configid = pco.id AND
 hco.optionid = pcos.id AND
 hco.relid = h.id AND
 c.id = h.userid AND
 p.id = h.packageid AND
 p.gid = 3 AND
 pco.optionname = 'Bandwidth';"`

echo $DATA_TO_GATHER

 

However it outputs like this:

userid serviceid config_option_value dedicatedip 2 26 2000GB Total 123.4.5.6

 

 

For some reason it is all on 1 line instead of 2

Link to comment
Share on other sites

Getting a syntax error with the following:

 

DATA_TO_GATHER=`mysql -u xxxxx --password='xxxxx' -D whmcs -BNe \
"QUERY
 c.id AS userid, h.id AS serviceid, pcos.optionname AS config_option_value, dedicatedip
FROM
 tblhosting h, tblclients c, tblproducts p, tblproductconfigoptionssub pcos, tblproductconfigoptions pco, tblhostingconfigoptions hco
WHERE
 pcos.configid = pco.id AND
 hco.configid = pco.id AND
 hco.optionid = pcos.id AND
 hco.relid = h.id AND
 c.id = h.userid AND
 p.id = h.packageid AND
 (p.gid = 3 OR
 p.gid = 4)
 pco.optionname = 'Bandwidth';"`

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