Dynamically display content without having to write a lot of mysql commands?
I hope this is the correct forum for this question!
I'm new to mysql/php but I've always wondered how certain websites display content on a per-location basis? I'm quite certain these websites don't write 100s or 1000s of mysql commands but I would like to know how their information is displayed.
For example, SELECT * FROM car_info WHERE state='massachusetts' The reason why I don't believe they have unique mysql commands like this is because they would have to write 1000s of commands and it would be too time consuming as a web developer to do so. My question is, how are pages like this programmed without having to write 1000s of mysql commands? How do they "show/present" content that's unique to the page and visitor?
Thanks for the response. Yes, that makes sense but now I'm a little confused on something else. If each state/city is a $location variable then how does that specific page know to get data that relates specifically to that state/city?
For example, in the "boston" section of cars.oodle.com/used-cars/boston-area/ hows that that specific page know how to "pull/get" data that relates to boston and not NYC, Las Vegas or even Miami? If all your using is a $location variable wouldn't your php page get confused as to what information to "show/present" to the visitor?
This is what I think what is happening with the above pages. Please tell me if I'm correct or totally wrong.
The page(s) inherent in a another page. Let's called this page init.php
include once "init.php";
In this init.php page a mysql commands takes place.
SELECT * FROM car_info WHERE state='massachusetts'
Then all of the mysql data is converted into $variables and is used on each indivual state/city page?
So in other words, for every state you would need to inherent a different init.php page with a different mysql command. Am I correct or totally wrong?
If the url is cars.oodle.com/used-cars/boston-area/ then probably we're talking "pretty urls", and the 'used-cars' and 'boston-area' part will be available to the php script as variables (through url rewriting and/or the use of a router class in the code). And those variables will be used to dynamically create a query with the correct values in the WHERE conditions.
So they only need 1 query, and put the right values in the WHERE conditions.
I'm not sure I completely understand the follow-up question. But, essentially, there is only one page. It receives the location as a parameter. The PHP logic then creates, on the fly, the content for the specific location. It either displays that content immediately, or (less likely) it creates a new page and redirects to it. This is basically how all data-based sites work. There is no question of the content being pre-written for each location, nor do the programmers need to even know which locations exist.