php - 内连接不起作用

标签 php mysql sql

大家好,请帮我解决这个从四个表中获取数据的查询。这是编写查询的正确方法吗

SELECT task.employee_id , task.user_id , task.service_id from task 
INNER JOIN employee  employee.name , employee.pic ON employee.pno =employee_id 
INNER JOIN user  user.name , user.pic ON user.pno = user_id 
INNER JOIN service  service.name , service.description ON service.service_id =service_id";

当我获取数据时,我将如何像我们一样显示它们 $a = $data['id'];

并且出现错误

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result,

现在我已经更新到此

function viewAll()
{


$this->query = "SELECT task.employee_id , task.user_id , task.service_id, employee.name , employee.pic, user.name , user.pic, service.name , service.description
FROM task  INNER JOIN employee  ON employee.pno = task.employee_id  INNER JOIN user  ON user.pno = employee.user_id  INNER JOIN service  ON service.service_id = user.service_id;";



$rd = $this->executeQuery();
$recordsArray = array(); // create a variable to hold the informationm
while (($row = mysqli_fetch_array($rd)) ){
$recordsArray[] = $row; // add the row in to the results (data) array
}

我收到此错误

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result,

最佳答案

不,这不正确。

SELECT task.employee_id , task.user_id , task.service_id, employee.name , employee.pic, user.name , user.pic, service.name , service.description
FROM
    task 
    INNER JOIN employee  ON employee.pno = task.employee_id 
    INNER JOIN user  ON user.pno = employee.user_id 
    INNER JOIN service  ON service.service_id = user.service_id;

我无法告诉你它到底应该是什么,但应该更接近。我根据原始查询对您的连接和列名称进行了最佳猜测。您想要“查看”的所有字段都需要位于 SELECT 子句中。当您加入另一张 table 时,您需要解释如何加入。例如,您要从 task 加入 employee,因此我假设 task 有一个名为 emmployee_id 的列(或者类似)这是您需要加入的领域。

关于php - 内连接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5440319/

相关文章:

php - Codeception vs peridot + php-webdriver?

php - 从某个页面重定向到另一个页面时如何获取引用 URL

performance - mysql查询+性能

如果两个字符串共享任何字符,SQL 则返回 TRUE

sql - 在 INSERT 时获取标识列值

javascript - 使用 javascript 对外部 url 发出 Ajax 请求

mysql - 这个mysql语句有什么问题

php - 使用 PHP 显示数据库中的记录

sql - 如何将SQL Server 2012数据库还原到SQL Server 2008 R2?

php - Applescript 可以发送获取或发布请求吗?