简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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