Pushpendra Kuntal
Pushpendra Kuntal

Reputation: 6186

How can i retrieve data from a table?

I am working in PHP. This is my query:

$sql = "SELECT * 
        from place as s 
        where checkDistance($lati1,$longi1,s.lat,s.lon)<$dist";

This place table has three fields: placeId, PlaceName and Address. Now I want to calculate rating of placeId which are the result of above query. To calculate the rating I have another table rating in which there are two fields: placeId and noOfPerson.

Rating will be calculated by (noOfPerson/maximum_no_of_person) for each placeId. How can i implement this?

Upvotes: 0

Views: 84

Answers (1)

k.m
k.m

Reputation: 31444

Your query could do majority of work here, this will select values from place table joined with number of person for each place, ordered by ranking you need, top-bottom:

SELECT s.placeid, s.PlaceName, s.Address, r.noOfPerson
FROM place as s JOIN rating as r ON (s.placeid = r.placeid)
WHERE checkDistance($lati1,$longi1,s.lat,s.lon)
ORDER BY r.noOfPerson / ( SELECT MAX(noOfPerson) FROM rating ) DESC

Upvotes: 2

Related Questions