简体   繁体   English

从动态href链接php链接到另一个php页面

[英]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. 我正在显示来自MySQL数据库的结果集。 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 . 当我单击动态生成的H3课程$ row ['title']时,我想链接到该课程的动态创建的独立页面,而不必制作100个单独的页面。 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']? 它是一个在['title']中传递了if语句的模板页面吗? 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. 打印结果时,只需将href添加到具有某些唯一值作为参数的新页面即可唯一地标识结果。 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'] . 然后,在new_page.php中,您可以通过$_GET['id']访问unique_id。 So you can query and echo the results as you want. 因此,您可以根据需要查询和回显结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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