php - 为标签命名并调用 if isset 函数

标签 php html mysql

我不得不说三个超链接,其中我给了它们重定向的名字 取决于点击的链接。 请求的页面是一个但内容不同(动态)。 这是我的代码:

<?php
    session_start();
    if(isset($_GET['class'])){
       $sql = "SELECT * FROM Notes WHERE class = class1";
       header("location: subjects.php");
    }
    else if(isset($_GET['class2'])){
           $sql = "SELECT * FROM Notes WHERE class = class2";
              header("location: subjects.php");
    }
    else if(isset($_GET['class3'])){
           $sql = "SELECT * FROM Notes WHERE class = class3";
              header("location: subjects.php");
    }
    else{
    header("location: classes.php");
    }
?>

这是带有名称的 html 超链接:

<a href="" name="class1"> Class 1 </a>
<a href="" name="class2"> Class 2 </a>
<a href="" name="class3"> Class 3 </a>

最佳答案

formname 属性作为参数构建 GET 请求。使用您的方法,您需要在 href 中构建 GETname 不会像使用 form< 那样处理.

<a href="?class1=true" name="class1"> Class 1 </a>

关于php - 为标签命名并调用 if isset 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51694800/

相关文章:

php - 从mysql中选择时间戳

PHP array_sum 输出单个数字而不是整体

php - 万无一失的 URL 独特标题

javascript - 修改 jquery 幻灯片代码以自动播放

html - 容器移动同时减小浏览器窗口

html - IE8 按钮的 CSS "initial"值

MYSQL IN优化

Mysql order by string of part OR Symbol after some int

php - Laravel:如何获取嵌套模型

php - 使用 PHP 创建分析图表