How to generate page content from database the right way?

I am creating many pages and store them into the database. I am first styling them and than storing them. The idea is to use page.php to check the page id and display the needed post. This is all good, but I have many pages in the website. WHich means I have to perform the following statement many time.

<?php        
 if(is_page(14)) {
   global $wpdb;
   $findContent = $wpdb->get_var("SELECT post_content  FROM wp_posts WHERE post_title = 'Why ......'");
    get_template_part( 'localnav' );
    echo $findContent;
  }
?>

My question is is that a good rpactice or is there a better idea?
Note there asome pages which look alike, maybe I can create catogories, but is it possible to select part of the content and put it in a div for example?

Solutions Collecting From Web of "How to generate page content from database the right way?"

WordPress is fetching current post for you, you have to only type to the right url. When you get e.g. to example.com/lorem-ipsum/ WordPress will load automatically post with title Lorem ipsum and display it using page.php template. Your page.php template should be looking something like that.

<?php get_header(); ?>

    <div id="content">

        <?php while ( have_posts() ) : the_post(): ?>

            <h1><?php the_title(); ?></h1>
            <?php the_content(); ?>

        <?php endwhile; ?>
    </div>

<?php
get_sidebar();
get_footer();

The concept of a loop is difficult to understand for novice developers. Only in the loop you can use functions like the_title orthe_content. Outside of the loop, these functions won’t return you anything.

https://codex.wordpress.org/The_Loop