这是当前代码,但它所做的只是从 1 行中选择列。
<?php
session_start();
include 'sqlconnection.php';
$conn = OpenCon();
$stmt = $conn->prepare('SELECT uid,coverphoto,profilepic,bio FROM profile WHERE uid = ?');
$stmt->bind_param('i', $_SESSION['uid']);
$stmt->execute();
$stmt->bind_result($uid,$coverphoto,$profilepic,$bio);
while($stmt->fetch()) {
$output=array(
'uid' => $uid,
'coverphoto' => $coverphoto,
'profilepic' => $profilepic,
'bio' => $bio
);
}
$json=json_encode($output);
echo $json;
$stmt->close();
CloseCon($conn);
?>
如何为此添加 if 语句,以便如果 coverphoto 和/或 profilepic = null,手动将值分配给输出数组的 coverphoto 和 profilepic?我将在下面显示我的错误尝试:
<?php
session_start();
include 'sqlconnection.php';
$conn = OpenCon();
$stmt = $conn->prepare('SELECT uid,coverphoto,profilepic,bio FROM profile WHERE uid = ?');
$stmt->bind_param('i', $_SESSION['uid']);
if ($stmt->execute()){
if (coverphoto=null){
$coverphoto = 'coverphoto.jpg';
}else{
if (profilepic=null){
$profilepic = "profilepic.jpg";
}else{
$stmt->bind_result($uid,$coverphoto,$profilepic,$bio);
while($stmt->fetch()) {
$output=array(
'uid' => $uid,
'coverphoto' => $coverphoto,
'profilepic' => $profilepic,
'bio' => $bio
);
}
}
}
}
$json=json_encode($output);
echo $json;
$stmt->close();
CloseCon($conn);
?>
牛魔王的故事