Display single post inside accordion based on form submission results

Closing off as the issue is resolved. For anyone interested, the result is as follows (refer to the code detailed above for the initial DB-table connections, as the code below refers to the output only):

if (isset($SelectedLocationID) && isset($SelectedSchoolID)) { ?>
<div id="resultsDiv">
  <div id="resultsHead">
    <h3>Search results for routes between:</h3>
    <b><?php echo $selectedLocationName; ?></b>
    and <b><?php echo $selectedSchoolName; ?></b><br />

    (Click on route to view timetable and map)
  </div>

  <?php
  if ($getRouteID) { ?>
  <div id="routeResult">
    <div id="accordion">
    <?php
    foreach ($getRouteID as $route) {
      // Break the getRouteID results into separate variables
      $RouteName = $route->Name;
      $RouteID = $route->RouteID;
      $RouteDescription = $route->Description;
      $RoutePageID = $route->RoutePageURI;

      $getPost = $wpdb->get_results(
        $wpdb->prepare (
          "SELECT post_content, post_name
          FROM m6anby77we_posts
          WHERE post_name="%s"", $RoutePageID
        )
      );

      foreach ($getPost as $post) {
        $pName = $post->post_name;
        $pContent = $post->post_content;

        ?>
        <div class="accordion-header">
          <h4>Route: <?php echo $RouteName;?> <?php echo $RouteDescription;?></h4>
        </div>
        <div><?php echo $pContent; ?></div>
        <?php
      }
    }
    ?>
    </div>
  </div>
<?php } else { ?>
  <div id="routeResult">
    <h4>Results:</h4>
    No Route found for your selection.<br />
  </div>
<?php } ?> </div> <?php } ?>

Only trick/ painful thing is that the post content is brought in as a string (to be expected) – so you’ll have to go into the text editor within each post to ensure that you’ve formated it properly in there so that the string can then be printed as html.

Have fun y’all