这应该真的很容易。我将根据你想要检索的内容和手头的信息向你展示不同的方法。当然,我知道您所知道的是fieldname,但我建议您进入您的WHMCS 安装的tblcustomfields 表并检索该自定义字段的id 值。现在让我们开始看代码:
首先:包含以下代码:
require("init.php");
use WHMCS\Database\Capsule;
第二:声明已知变量:
我假设您已经拥有您所知道的价值观。所以我将在这里使用我的伪值:
$clientID = 12;
$customFieldID = 1;
$customFieldName = 'Where did you hear about us?';
第三:添加检索数据的代码
我将使用四个代码。选择最适合您需要的套件。
答:获取 1 个客户的自定义字段值。您有客户 ID 和自定义字段名称
$customFieldValue1 = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
->where('tblcustomfieldsvalues.relid','=',$clientID)
->where('tblcustomfields.fieldname','=',$customFieldName)
->value('tblcustomfieldsvalues.value');
//Use the retrieved vaue e.g echo
echo $customFieldValue1."<br/>";
B:获取 1 个客户的自定义字段值。您有客户 ID 和自定义字段 ID
$customFieldValue2 = Capsule::table('tblcustomfieldsvalues')
->where('relid',$clientID)
->where('fieldid',$customFieldID)
->value('value');
//Use the retrieved vaue e.g echo
echo $customFieldValue2."<br/>";
C:获取所有客户端的自定义字段值。您有客户 ID 和自定义字段名称
$customFieldValues1 = Capsule::table('tblcustomfields')
->join('tblcustomfieldsvalues','tblcustomfieldsvalues.fieldid','=','tblcustomfields.id')
->select('tblcustomfieldsvalues.value as value','tblcustomfieldsvalues.relid as client')
->where('tblcustomfields.fieldname','=',$customFieldName)
->get();
//use retrieved values
foreach($customFieldValues1 as $customField){
$clientId = $customField->client;
$customFieldValue = $customField->value;
echo $clientId." : ".$customFieldValue."<br/>";
}
C:获取所有客户端的自定义字段值。您有客户 ID 和自定义字段 ID
$customFieldValues2 = Capsule::table('tblcustomfieldsvalues')
->select('relid as client','value')
->where('fieldid',$customFieldID)
->get();
//use retrieved values
foreach($customFieldValues2 as $customField){
$clientId = $customField->client;
$customFieldValue = $customField->value;
echo $clientId." : ".$customFieldValue."<br/>";
}
如果这回答了您的问题,请告诉我。
有关如何使用 WHMCS 目前用于与数据库交互的 laravel 编写查询的更多信息,您可以访问https://laravel.com/docs/5.2/queries