我有一个users
表,id
作为主键,leads
表,id
作为外键。我想通过users
的id
显示用户表中的信息以及leads
表中的id
:
public function query($sql, $params = array()) {
$this->_error = false;
if($this->_query = $this->_pdo->prepare($sql)) {
$x = 1;
if(count($params)) {
foreach($params as $param) {
$this->_query->bindValue($x, $param);
$x++;
}
}
if($this->_query->execute()) {
$this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ);
$this->_count = $this->_query->rowCount();
} else {
$this->_error = true;
}
}
return $this;
}
public function get($table, $where) {
return $this->action('SELECT *', $table, $where);
}
你编码过吗?您需要使用联接。
Select u.id , l.id from users u, leads l where u.id = l.user_id
或
所有数据 FRM 用户,仅 ID FRM 潜在客户
Select u.* , l.id from users u, leads l where u.id = l.user_id
假设潜在客户表中的列名user_id
SELECT u.*, l.id
FROM users u
JOIN leads l ON u.id = l.id
这对你来说可能是一个开始