如何从两个SQL表中获取数据以在PHP网页上显示 [英] How to get data from two SQL tables to show on PHP web page
问题描述
我想从课程表中获取C_ID并从学生表中获取名称,并希望在网页上显示更新clist.php //我的网页名称,我想要显示这些值。
我尝试了什么:
<?php
$ servername = localhost;
$ username =root;
$ password =;
$ dbname =college;
//创建连接
$ conn = new mysqli($ servername,$ username,$ password,$ dbname);
//检查连接
if($ conn-> connect_error){
die(Connection failed:。$ conn-> connect_error);
} < br $>
// $ result = mysqli_query($ conn,SELECT * FROM studentcourse);
$ result_c = mysqli_query($ conn,SELECT studentID,C_ID
FROM [学生]加入[课程]
ON [studentcourse] .studentID = student.ID);
echo
;
while($ row = mysqli_fetch_row(($ result_c) )
{
echo;
echo;
echo;
echo;
}
echo
名称 | < th>课程名称|
---|---|
。 $ row ['name']。 | 。 $ row ['C_Name']。 |
$ conn-> close();
?>
i want t get the C_ID from course table and name from student table and want to show it on webpage updatesclist.php // my webpage name where i want to show these values.
What I have tried:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "college";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$result = mysqli_query($conn,"SELECT * FROM studentcourse");
$result_c = mysqli_query($conn,"SELECT studentID, C_ID
FROM [student] JOIN [course]
ON [studentcourse].studentID=student.ID ");
echo "
";
while($row = mysqli_fetch_row(($result_c))
{
echo "";
echo "";
echo "";
echo "";
}
echo "
Name | Course Name |
---|---|
" . $row['name'] . " | " . $row['C_Name'] . " |
$conn->close();
?>
推荐答案
servername =localhost ;
servername = "localhost";
username =root;
username = "root";
password =;
password = "";
这篇关于如何从两个SQL表中获取数据以在PHP网页上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!