如何在其他页面中使用返回变量值


how use return variable value in other page

你好,我试图在选择查询pdo中使用OOP概念。我想在HTML中选择标签加载数据库值。以下是选择标签编码。

<?php includer='function.php'; ?>
<select class="form-control" id="old_category" name="old_category">
                                    <option value="0"  >---</option>
                                    <?php 
                                    $sql= new items();
                                    $sql->show_register_items_category();
                                    foreach($sql as $row){
                                    ?>
<option><?php echo $sql;?></option>
<?php } ?>
</select>

在function.php文件中,我创建了以下代码:

<?php
include_once '../db/connection.php';
$con=new connection();
$dbg=$con->db;

class items
{
    public function show_registered_items_category()
    {
        $sql="SELECT `category` FROM `available_items` GROUP BY `category` ORDER BY `category` ASC";
        this.$stmt=$dbg->query($sql);
        $row=$stmt->fetch(PDO::FETCH_ASSOC);
        //return $stmt;
        return $rows;
    }
}

请有人告诉我如何在其他文件中使用此返回变量$rows

<?php includer='function.php'; ?>
<select class="form-control" id="old_category" name="old_category">
     <option value="0"  >---</option>
     <?php 
     $sql= new items();
     //this is how you use this return variable $rows in other file.
     $rows=$sql->show_register_items_category();
     //haven't checked the foreach
     foreach($rows as $row){
     ?>
     <option><?php echo $row;?></option>
<?php } ?>
</select>