gpt4 book ai didi

mysql 查询到 drupal 查询

转载 作者:行者123 更新时间:2023-11-29 04:50:58 25 4
gpt4 key购买 nike

任何人都可以将此查询转换为 drupal db_select

    $query="SELECT DISTINCT 'supplier_id','supplier_name','supplier_address','supplier_city', 'supplier_pincode', 'supplier_state', 'supplier_country' FROM pmai_supplier_directory WHERE ";
foreach($list as $k=>$value)
{
$query.=" supplier_interest LIKE '%".$value."%' OR";
}
$query=substr($query,0,strlen($query)-2);
echo $query.=" ORDER BY supplier_name";

谢谢

最佳答案

所以查询是:

SELECT DISTINCT 'supplier_id','supplier_name','supplier_address','supplier_city',
'supplier_pincode', 'supplier_state', 'supplier_country'
FROM pmai_supplier_directory
WHERE supplier_interest LIKE '%foo%'
OR supplier_interest LIKE '%bar%'
OR supplier_interest LIKE '%baz%'
ORDER BY supplier_name";

可以这样做:

$list = array('foo','bar','baz');
$query = db_select('pmai_supplier_directory','pmsp')

->fields('pmsp',array(
'supplier_id',
'supplier_name',
'supplier_address',
'supplier_city',
'supplier_pincode',
'supplier_state',
'supplier_country'
))
->orderBy('supplier_name')
->distinct();

$orCond = db_or();$elt = 0;
foreach($list as $k => $value) {
$orCond->condition('pmsp.supplier_interest','%'.$value.'%','LIKE');
$elt++;
}
if ($elt) {
$query->condition($orCond);
}

然后您只需执行并获取结果即可。

关于mysql 查询到 drupal 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11668382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com