【发布时间】:2015-06-26 14:53:06
【问题描述】:
我正在尝试获取类中函数的值。
classes.php
class luresClass {
public function lureSelect() {
global $lureChoice;
if ($_POST['airtemp'] == 2 && $_POST['watertemp'] == 5) {
$lureChoice = 1;
}
else {$lureChoice = 0;}
}
}
这是需要访问$lurechoice值的主文件(index.php)。
if (isset($_POST['submit'])) {
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$displayLureChoice = new luresClass();
$displayLureChoice->lureSelect();
$stmt = $conn->prepare("SELECT * FROM ".$tbl."lure WHERE id = ".$lureChoice."");
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "Lure Choice: ".$row['type']. "<br />Color: " .$row['color']. "<br /><br />";
}
}
用户从表单中选择某些项目,然后返回 if/else 值。
我尝试在 classes.php 文件中的函数 lureSelect() 中将 $lurechoice 设为全局变量,但不起作用。我尝试将其设为课堂上的公共变量,但也失败了。
感谢您的指导。
【问题讨论】: