Let’s see on some examples of dynamic websites first.
- facebook.com when you visit facebook after login you go to your home page which is actually home.php file of facebook where you see latest updates by your connections which get changed on daily basis as your connections update their profile. That does not mean facebook edit home.php file in their server for you daily even that home.php is single in facebook server and used for millions of users which get user id dynamically when he/she is loged in then doing server side programming facebook get updates dynamically from your connections in home.php.
- youtube.com There are thousands of videos in youtube what do you think youtube have seprate file for all different videos in their server? No! videos are saved in youtube server’s directory and the path to that video saved to database, title of video, description, tags, and other information saved in database where youtube give an id to that video and using that id from youtube url youtube loads all related information about that video including video in page so video page is single for all thousands of videos. Same for youtube home page when you login home page show updates from channels you have subscribed, likes related videos you liked before and much more.
- An online shop: When you go to an online shop there you may will have latest products section in home page, featured products in home page and other options. Each product from latest section, featured section, categories, products page when you open any product that open in same way for all products so the product page getting data about product from database and showing in way you have programmed. In same shop you have add to cart functionality where you add products in cart once you have bought them that shopping website will reduce products from their stock automatically and update income as your purchase.
- Blogs or cms: Content management system like wordpress, blogger or custom CMS you developed with php. You can add new blog posts, new pages, new categories you can edit existing posts, pages, categories and those will update in all pages automatically. That means there is only 1 structure for page layout in your server, and 1 layout for home page, and 1 layout for single post where you show as many as posts, pages, categories you want.
In dynamic websites things do not repeat if you have same header, footer, navigation, side bar in all pages and you want to make a change in anything of these you will do that just once in header.php , footer.php or sidebar.php that will be changed in all pages automatically. This is dynamic website.