我一直在互联网上寻找解决我的问题的方法。我正在自学关系数据库,并试图在我的网页上回应这一点。但它没有回显:(
请用一双新的眼睛看看我的代码并为我指明正确的方向。 非常感谢
为了自己的目的,我一直在尝试在编辑之前进行测试运行
database: fault
table: user
collumns: id name course
foreign key(fk_course)fault,course,id
table: course
Collumns: id coursename
代码:
<?php
require 'connection.php';
//where statement in the sql syntax will select where in db to get infor, use AND to add another condition
$result = mysqli_query($con,"SELECT user.name, course.coursename FROM 'user' INNER JOIN 'course' ON user.course = coursename.id"); //this creates a variable that selects the database
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Course</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['coursename'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
最佳答案
您的 SQL 语句应如下所示:
SELECT user.name,
course.coursename
FROM user INNER JOIN course ON user.course = course.id;
对字符串使用普通撇号,并且 ON
部分应正确匹配字段。
关于php echo并加入mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18082322/