Relational databases are a fairly large concept. There are numerous tutorials online that cover a lot more than I'd be able to type up here. But in essence, relational databases are databases that have relations to other ones. So instead of storing the data in a CSV format they each have their own row in a separate table and they are linked together. This is faster, less error prone, more flexible and overall a much better practice. Again, there are extensive tutorials that you can find on Google for this subject.
Once you understand relational databases queries get more efficient (although a little harder to write). The script you have there could be done in one single query with a properly designed database. To give you an example here is how I would do the above:
table users:
user_id int(9) primary_key, auto_incriment
user_name varchar(255)
ect...
table places:
place_id int(9) primary_key, auto_incriment
place_name
table ratings
rating_id int(9) primary_key, auto_incriment
rating_place_id int(9)
rating_user_id int (9)
rating_score int(1) //0=thumbs down, 1=thumbs up
This would get ratings by place:
SELECT COUNT(rating_id), place_name FROM places LEFT JOIN ratings ON rating_place_id=place_id GROUP BY place_name
Example output:
10 | Chicago
8 | New York
15 | Paris
This would get ratings for a particular user:
SELECT rating_score, place_name FROM ratings LEFT JOIN places ON rating_place_id=place_id WHERE ratings_user_id=[USER_ID]
Example output:
1 | Chicago
0 | Paris
1 | New York
|