I am trying to set a sql query that will show jobs from a selected type of trade and within certain distance. 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
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
}
}
?>