html—如何使用pdo fetch方法从php中的数据库中获取特定的值集?

62lalag4  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(244)

我有一个library.php,在那里编写函数,一个特定的函数get\u channels被编写来获取属于customer\u id的所有值。我使用pdo,我想在这个函数中执行并获取值,结果必须显示在另一个页面的前端。但此函数不显示属于customer id的表的任何名称。
library.php中的函数

public function get_channels($cust_id)
{
    try {
        $db = DB();
        $query = $db->prepare("SELECT * FROM sensor_table WHERE customer_id=:customer_id");
        $query->bindParam("customer_id", $cust_id, PDO::PARAM_STR);
        $query->execute();   
        return $query;
    } catch (PDOException $e) {
        exit($e->getMessage());
    }
}

前端网页中的代码:

<div id="main-content">

            <?php 

            $count=$app->get_channels_count($customer->customer_id);
            $values=$app->get_channels($customer->customer_id);
            $channel_name=$values->fetch(PDO::FETCH_OBJ);
            echo $channel_name;
            for($i=0;$i<$values->rowCount();$i++)
            {

            ?>

            <div class="col-lg-3">
                        <div class="card alert">
                            <div class="products_1 text-center">
                                <div class="pr_img_price">
                                    <div class="product_img">
                                        <img src="assets/images/product_1/download.jpg" alt="" />
                                    </div>

                                </div>

                                <div class="product_details">
                                    <div class="product_name">
                                        <h4><?php echo $channel_name['table_name'];  ?></h4>
                                    </div>
                                    <div class="product_des">
                                        <p>Vimply dummy text the printing and type setting indust.</p>
                                    </div>
                                    <div class="prdt_add_to_cart">
                                        <button type="button" class="btn btn-primary btn-rounded  m-l-5">add to cart</button>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <!-- /# card -->
                    </div>

                <?php
            }
            ?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题