php - 显示用户表和潜在客户表中的数据

标签 php mysql

我有一个以 id 作为主键的 users 表和一个以 id 作为主键的 leads 表外键。我想通过 usersid 以及来自 leadsid 显示用户表中的信息> 表:

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 是销售线索表中的列名

关于php - 显示用户表和潜在客户表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19928240/

相关文章:

php - 如何保护按许可证销售的 Web 应用程序免受盗版?

php - 使用 PHP 在 mysql 表中搜索标签

php - 如果用户名不在日志中设置为脱机

java - 使用Java将数据从一个数据库导入到另一个数据库的最快方法

MySQL触发代码根据另一个值输入语句

php - 如何自动生成黑白版图片

php - Memcached 存储用户账户

php - Laravel app boostraps 在测试环境的早期

php - sql连接单个条目与多个条目表的总和

php - MYSQL 我可以更改如何动态限制结果吗?