请帮忙。我需要打印此查询的结果但没有出现
$fetch_a = "
SELECT
programs.Program_Description
FROM
programs
WHERE
programs.Programid =
('
SELECT
memberprogram.Programid
FROM
memberprogram
WHERE
memberprogram.Memberid = $Memberid &&
memberprogram.Option_No = 'Option A'
')
";
$result_a = mysqli_query($dbc, $fetch_a);
echo $result_a;
答案 0 :(得分:1)
您应首先使用fetch_row或fetch_array
mysqli_fetch_row 例如:
while($row=mysqli_fetch_row($result_a))
echo $row[0]."<br/>";
编辑: 就查询而言:
答案 1 :(得分:0)
好的,首先是你的查询是一团糟。如果不知道架构设计的细节,我会猜测这个
// note I'm using HEREDOC format
$sql = <<<_SQL
SELECT p.Program_Description
FROM programs p
WHERE EXISTS (
SELECT 1 FROM memberprogram m
WHERE m.Option_No = 'Option A'
AND m.Memberid = ?
AND m.Programid = p.Programid
)
_SQL;
然后,您应该使用参数绑定与预准备语句。例如
$stmt = $dbc->prepare($sql);
$stmt->bind_param('i', $Memberid); // assuming $Memberid is an integer
$stmt->execute();
$stmt->bind_result($programDescription);
$stmt->fetch();
$stmt->close();
echo $programDescription;