我想一一获取变量我做错了什么,为什么我不能把所有的数组都回显出来?
<?php
class get_all{
public $id;
public $product_name;
public $price;
public $date_added;
public $det;
function get_detais(){
$sql = mysql_query("SELECT * FROM products ORDER BY id DESC ");
$productCount = mysql_num_rows($sql); // count the output amount
$det=array();
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
}return $det=array($id,$product_name,$price,$date_added);
} else {
return $det= "We have no products listed in our store yet";
}
}
}
?>
在这里,我将函数称为数组元素:
<?php
$det=new get_all;
$det->get_detais();
echo $det[1];
?>