简体   繁体   中英

Linking to another php page from dynamic href link php

Can someone give me a bit of guidance on how to solve my problem? I am displaying a result set from mySQL db. It is a list of course names and accompanying details. When I click on the dynamically generated H3 course $row['title'], I want to link to a dynamically created stand alone page for that course, rather than have to make 100 separate pages . I've had a look around and can't find what I'm looking for. Would it be a template page that had an if statement that passed in the ['title']? A starting point on this would be a great help, thank you.

<section class="mainSection">
        <div class="searchResults">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <?php if( $row ){
                    while ($row = $result->fetch_assoc()){
                    echo '<h3 class="resultHeaders"><a href="#">' . $row['title'] . '</a></h3>';
                    echo '<p>' . $row['award'] . '</p>';
                    echo '<p class="summaryStyling">' . $row['summary'] . '</p>';
                    }

                    } else {
                    $no_course = 'No course found matching your search';
                    echo '<h3 class="resultHeaders">' . $no_course . '</h3>';
                    }

                    ?>
                    <div class="centerStuff"><a href="search-engine.php">Search Again?</a></div>
                </div>
            </div>
        </div>
</section>  

When printing the results, just add href to the new page with some unique value as a parameter to identify the result uniquely. For example,

<?php 
if( $row ){
    while ($row = $result->fetch_assoc()){
        //note the href url
        echo '<h3 class="resultHeaders"><a href="new_page.php?id=unique_id">' . $row['title'] . '</a></h3>';
        echo '<p>' . $row['award'] . '</p>';
        echo '<p class="summaryStyling">' . $row['summary'] . '</p>';
        }
} else {
    $no_course = 'No course found matching your search';
    echo '<h3 class="resultHeaders">' . $no_course . '</h3>';
}
?>

Then, in the new_page.php, you can access the unique_id by $_GET['id'] . So you can query and echo the results as you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM