繁体   English   中英

多个html href到php页面

[英]multiple html href to php page

我有一个html页面

<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php">Submitted Applications:</a></div>
        </form>
    </body>
</html>

我有一个PHP页面“ MySubmissionView.php”用于某些过程。 在我的php页面中,我如何知道我单击了哪个链接。

将查询字符串添加到您的href中。 例如,MySubmissionView.php?page = number和MySubmissionView.php?page = submitted。 您可以使用$_GET('paramname')从您的php访问查询字符串。 这是一个例子:

HTML

<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php?page=number">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php?page=submitted">Submitted Applications:</a></div>
        </form>
    </body>
</html>

PHP的

if (isset($_GET['page']))
  if($_GET['page'] == 'number') {
    // process page number here
  } elseif($_GET['page'] == 'submitted') {
    // process page submitted here
  }
}
<div><a href="MySubmissionView.php?id=xx1">Number of Applications:</a></div>
<div><a href="MySubmissionView.php?id=xx2">Submitted Applications:</a></div>

PHP页面:

if (!empty($_GET['id'])) {
    echo '<p>The id is: '.$_GET['id'].'</p>';
    // do something else
}
<html>
    <head>
    </head>
    <body>
        <form>
            <div><a href="MySubmissionView.php?click=1">Number of Applications:</a></div>
            <div><a href="MySubmissionView.php?click=2">Submitted Applications:</a></div>
        </form>
    </body>
</html>

MySubmissionView.php:

if($_GET['click'] == 1){
   echo "first a clicedk";
}else{
    echo "second a clicedk";
}
<html>
<head>
</head>
<body>
    <form>
        <div><a href="MySubmissionView.php?go=1">Number of Applications:</a></div>
        <div><a href="MySubmissionView.php?go=2">Submitted Applications:</a></div>
    </form>
</body>

上面是您的HTML,而MySubmissionView.php的PHP应该如下所示。

<?php
     $go = "";
       if(isset($_GET)){
            if(isset($_GET['go'])){
                $go = $_GET['go'];
            }else{
                // do something if '$_GET['go']' is not set
            }
      }else{
        // Do something if u don't get a $_GET Request
      }

    echo 'Clicked Page'.$go;
?>

-

 if(isset($_GET))

将检查页面是否获取/发布请求。 阅读有关获取/发布方法的信息

暂无
暂无

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

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