[英]storing value return by function in variable of if statement and use in other condition -php
[英]how use return variable value in other page
嗨,我正在嘗試在選擇查詢 pdo 中使用 OOP 概念。 我想在 HTML 的 Select 標簽中加載數據庫值。 以下是選擇標簽編碼。
<?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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.