首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >多查询PHP

多查询PHP
EN

Stack Overflow用户
提问于 2018-09-29 06:14:34
回答 1查看 0关注 0票数 0

我需要帮助你的代码,多查询,(3查询)

查询1确定,查询2:错误查询3:错误

码:

$query ="select id from res_partner where supplier =true and vat='$emirfct1[0]'";

$query2 ="select substring(value_reference from position(',' in value_reference)+1)::int4 account_id from ir_property where name = 'property_account_expense' and res_id = 'product.template,' || 294";

$query3 ="select supplier,employee from res_partner  where  id=$ac_id";




$result = pg_query($query);
$result2 = pg_query($query2);
$result3 = pg_query($query3);
echo $result;

if(pg_numrows($result) )
{
    if( $row = pg_fetch_assoc($result) )
        {
            $iderp= $row['id'];

    }
}

if(pg_numrows($result2) )
{
    if( $row2 = pg_fetch_assoc($result2) )
    {
        $ac_id= $row2['account_id'];

    }
}

if(pg_numrows($result3) )
{
    if( $row3 = pg_fetch_assoc($result3) )
    {
        $supplier= $row3['supplier'];
        $employee= $row3['employee'];
    }
}

代码中有什么问题?

我有时间寻找解决方案,但我找不到它,我希望得到你的帮助,你可以引导我找到解决方案

EN

回答 1

Stack Overflow用户

发布于 2018-09-29 15:49:09

$ac_id从第二个查询的结果设置变量之前,您尝试使用该变量。

您需要在此之后进行$query3分配和查询。

$query ="select id from res_partner where supplier =true and vat='$emirfct1[0]'";

$query2 ="select substring(value_reference from position(',' in value_reference)+1)::int4 account_id from ir_property where name = 'property_account_expense' and res_id = 'product.template,' || 294";

$result = pg_query($query);
$result2 = pg_query($query2);
$result3 = null;

if(pg_numrows($result) )
{
    if( $row = pg_fetch_assoc($result) )
    {
        $iderp= $row['id'];

    }
}

if(pg_numrows($result2) )
{
    if( $row2 = pg_fetch_assoc($result2) )
    {
        $ac_id= $row2['account_id'];
        $query3 ="select supplier,employee from res_partner  where  id=$ac_id";
        $result3 = pg_query($query3);
    }
}

if($result3 && pg_numrows($result3) )
{
    if( $row3 = pg_fetch_assoc($result3) )
    {
        $supplier= $row3['supplier'];
        $employee= $row3['employee'];
    }
}

您还可以使用这两个查询组合成单个查询 JOIN

select supplier, employee
from res_partner r
join join ir_property i on r.id = substring(i.value_reference from position(',' in i.value_reference)+1)::int4
where i.name = 'property_account_expense' and i.res_id = 'product.template,' || 294
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100002815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档