我正在尝试将$ data ['id']的值分配给这样的变量:
$totalfor = $data['id'];
但这不起作用,该值未传递到$ totalfor
如果我回显$data['id']
,它给出的正确值为85
我需要$data['id']
的值才能将其用于Select查询
有人知道实现此目标的正确语法吗? 谢谢
代码如下:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
$jury = get_active_user('accountname');
$totalfor = $data['id'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT total AS total FROM votestepone WHERE votefor = '$totalfor' AND votedby= '$jury'";
$result = $conn->query($sql);
if ($result = mysqli_query($conn, $sql)) {
while ($row = mysqli_fetch_assoc($result)) {
$totalvote = $row["total"];
}
} else {
echo "0 results";
}
?>
<?php echo $totalvote; ?>
错误是:未定义变量:totalvote
如果我设置 $ totalfor = 85; ->有效 但我需要使用来自$ data ['id'];
的值我在查看页面中,$ data ['id']来自:
$data = $this->view_data;
如果我<?php echo $data['id']; ?>
显示85