Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Foreach循环键值作为类对象调用中的参数_Php - Fatal编程技术网

Php Foreach循环键值作为类对象调用中的参数

Php Foreach循环键值作为类对象调用中的参数,php,Php,我有一个PDO查询结果(数组),foreach循环将生成两个包含 根据行数[rows=elements]从每行获取的值 因此,基本上是当尝试调用名为getBusinessName的类对象,并将键值作为参数时,该方法不提供任何输出,我还尝试传递一个包含键值的定义变量,并且相同的条件没有错误,只有一个空格,调用没有响应 $db->getBusinessName public function getBusinessName($sql, $params = array()){

我有一个PDO查询结果(数组),foreach循环将生成两个包含 根据行数[
rows=elements
]从每行获取的值

因此,基本上是当尝试调用名为
getBusinessName
的类对象,并将
键值
作为参数时,该方法不提供任何输出,我还尝试传递一个包含
键值的定义变量
,并且相同的条件没有错误,只有一个空格,调用没有响应

$db->getBusinessName

    public function getBusinessName($sql,  $params = array()){
        if($this->connected === true){
            try{
                
                $q = $this->connection->prepare($sql);
                $q->execute($params);
                return $q->fetchColumn();
                
            }
            catch(PDOException $e){
                if($this->errors === true){
                    return $this->error($e->getMessage());
                }else{
                    return false;
                }
            }
        }else{
            return false;
        }
    }


//关键值//

好的,那么下面的更新不起作用

<center><?php echo $db->getBusinessName("SELECT companyarabname FROM accounts WHERE ID='.$id.'"); ?></center> 

您可能需要
echo
您的
$db->getBusinessName()
调用?@mikerojas否不需要echo,因为调用将从
pharmacyid
列返回字符串值。对,但该值是如何显示的。正如您所说,它返回一个字符串值,但当您调用它时,您并没有回显返回的值。还是我遗漏了什么?@mikerojas是的,您遗漏了以确保我没有错,我用整数
1
而不是
$id
调用了该方法,它工作了,还尝试在变量中定义调用并使用了(var_dump),输出是
bool(false)
非常感谢您,Seconde工作了
<HTML>
<body>
 <?php $AcBilling = $db->getRows('SELECT * FROM `bills` WHERE statues=true ORDER BY billingdate DESC')?>
            <div class="container-fluid bg-light">
                <?foreach($AcBilling as $activebill){
                    $id = $activebill['pharmacyid'];?> // The key-value //
                    <!-- invoice template -->
                    <div id="<?=$activebill['invoicecodenum']?>" role="tablist" aria-multiselectable="true">
                        <div class="card">
                            <div class="card-header" style="font-family:hana;" role="tab" id="section1HeaderId" data-toggle="collapse" data-parent="#<?=$activebill['invoicecodenum']?>" href="#section1Content<?=$activebill['invoicecodenum']?>" aria-expanded="true" aria-controls="section1ContentId">
                                <span class="float-left"> <strong>الحالة:</strong> <span style="color:orange;">معلقة</span></span>
                                <h5 class="float-right">طلبية <span id="date" style="font-family:Tahoma !important;">: 12\2\2020</span></h5>
          // The function //     <center><?$db->getBusinessName("SELECT companyarabname FROM accounts WHERE ID='.$id.'"); ?></center> 
                            </div>
</body>
</HTML>

<center><?php echo $db->getBusinessName("SELECT companyarabname FROM accounts WHERE ID='.$id.'"); ?></center> 
<center><?= $db->getBusinessName("SELECT companyarabname FROM accounts WHERE ID='.$id.'"); ?></center>