【问题标题】:Linking to another php page from dynamic href link php从动态href链接php链接到另一个php页面
【发布时间】:2016-04-15 08:36:42
【问题描述】:

有人可以就如何解决我的问题给我一些指导吗?我正在显示来自 mySQL db 的结果集。它是课程名称和随附详细信息的列表。当我点击动态生成的 H3 课程 $row['title'] 时,我想链接到为该课程动态创建的独立页面,而不是必须制作 100 个单独的页面。我环顾四周,找不到我要找的东西。它会是一个模板页面,它有一个在 ['title'] 中传递的 if 语句吗?对此有一个很大的帮助,谢谢。

<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>  

【问题讨论】:

  • 在页面上的 $_GET 方法中创建页面传递 id 使用 WHERE 条件进行查询

标签: php html mysql url


【解决方案1】:

打印结果时,只需将href添加到新页面,并带有一些唯一值作为参数,以唯一标识结果。例如,

<?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>';
}
?>

然后,在new_page.php 中,您可以通过$_GET['id'] 访问unique_id。因此,您可以根据需要查询和回显结果。

【讨论】:

  • 谢谢,Imesha,但是有机会怎么做 new_page.php 吗?
  • new_page.php 只是另一个文件,就像您在此处添加的文件一样。将其保存在与当前页面相同的目录中。
  • 对不起,你把我弄丢了。
猜你喜欢
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-02
  • 1970-01-01
  • 2017-08-12
  • 2020-11-10
  • 2021-03-16
相关资源
最近更新 更多