简体   繁体   English

使用 INNER JOIN 语句连接 3 个表的问题

[英]problem in joining 3 tables using INNER JOIN statement

I am trying to set a sql query that will show jobs from a selected type of trade and within certain distance.我正在尝试设置一个 sql 查询,该查询将显示来自选定贸易类型和一定距离内的工作。 I have three tables clients, traders and jobs.我有三张表客户、交易员和工作。 What I need is like-我需要的是——

SELECT * from jobs WHERE the type of job required matches by the type of jobs this trader offers AND the DISTANCE between the client and trader is within a range specified SELECT * from jobs WHERE 所需的工作类型与此交易者提供的工作类型相匹配,并且客户与交易者之间的距离在指定范围内

I have managed to get the first part done.我已经成功完成了第一部分。 it shows all jobs that match the types of job a trader offers, but struggling to get the second part.它显示了与交易者提供的工作类型相匹配的所有工作,但很难获得第二部分。 Here is my query这是我的查询

 $stmt=$pdo->prepare("SELECT jobs.*, clientPostcode, traderPostcode FROM jobs 
                        INNER JOIN traders ON FIND_IN_SET(jobs.tradeType,traders.tradeTypes ) WHERE traders.traderEmail=:traderEmail 
                        INNER JOIN clients ON jobs.clientEmail= clients.clientEmail" );
        $stmt->bindparam('traderEmail',$traderEmail);

    $stmt->execute();
            while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
                //calculate distance between origin and destination 
               IF (condition is ok){
                ?>
                <div class="card col-lg-12 mt-5 text-center">
                    <div class="card-body">
                        <h6 class="card-title text-primary">Job Type: <?php echo $row['tradeType'] ?> (Job Title: <?php echo $row['jobTitle'] ?> ) </h6>
                        <p class="card-text"><?php echo $row['jobDescription'] ?></p>
                        <a class="btn btn-primary" href="">
                        <i class="fas fa-edit fa-xs"></i> Send Interest</a>
                        <a class="btn btn-success" href="" target="_blank">
                        <i class="fas fa-glasses fa-xs"></i> Shortlist</a>
                    </div>
                </div>
                <?php
}
                    }
                ?>
$stmt=$pdo->prepare("SELECT jobs.*, clients.clientPostcode, traders.traderPostcode FROM jobs 
                    INNER JOIN traders ON FIND_IN_SET(jobs.tradeType,traders.tradeTypes )
                    INNER JOIN clients ON jobs.clientEmail= clients.clientEmail  WHERE traders.traderEmail=:traderEmail " );
$stmt->bindparam('traderEmail',$traderEmail);
    $stmt->execute();
        while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
            
            $origin      = $row['traderPostcode'];
            $destination = $row['clientPostcode'];

then I used google distance matrix api (cURL)to calculate distance between the two postcodes.然后我使用谷歌距离矩阵 api (cURL) 来计算两个邮政编码之间的距离。 I appreciate everyone for your time.我感谢大家的时间。 Will try to be more specific for future questions.将尝试更具体地解决未来的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM