duankange2433 2013-08-06 13:59
浏览 59
已采纳

php echo并加入mysql数据库

I have been trolling the internet for the solution to my issue. I am teaching myself relationship databasing and trying to echo this on my webpage. but it is not echoing :(

please can a fresh pair of eyes take a look at my code and point me in the right direction. many thanks

I have been trying to do a test run before editing for my own purposes

database: fault
table: user
collumns: id name course 
foreign key(fk_course)fault,course,id
table: course
Collumns: id coursename

Code:

<?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>";
?>
  • 写回答

3条回答 默认 最新

  • dongyou5271 2013-08-06 14:07
    关注

    You SQL statment should look like this:

    SELECT user.name,
           course.coursename
      FROM user INNER JOIN course ON user.course = course.id;
    

    Use normal aposthropes for strings and the ON part should correctly match the fields.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真