如果两个不同表中的两行都匹配,我会尝试生成一个结果,但我很难让它发挥作用。如果我遗漏了什么,有人可以告诉我吗..提前谢谢你
**注意:我的连接在一个包含的文件中,两个表在同一个数据库中
<html>
<p>Pending Documents</p>
<?php
$sql ="SELECT * FROM `forms`";
if ($_SESSION['user_name'] == $row["username"]){ ?>
<p><a href="">SUTA Document</a></p>
<? }else { ?>
<p>No Pending Documents</p>
<? } ?>
</html>
最佳答案
你应该用mysqli来解决。这是一个工作片段:
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . mysqli->connect_error;
}
if ($result = $mysqli->query("SELECT * FROM `forms`")) {
while ($obj = $result->fetch_object()) {
if ($_SESSION['user_name'] == $obj->username){ ?>
<p><a href="">SUTA Document</a></p>
<? }else { ?>
<p>No Pending Documents</p>
<? }
}
$result->close();
}
$mysqli->close();
?>
关于php - 如果两个语句都为真,则对产品数据进行 If 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27390604/