多个html href到php页面

时间:2014-08-01 06:25:06

标签: php html

我有一个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页面中我怎么知道我点击了哪个链接。提前谢谢

4 个答案:

答案 0 :(得分:2)

向您的hrefs添加查询字符串。例如MySubmissionView.php?page = number和MySubmissionView.php?page =已提交。您可以使用$_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
  }
}

答案 1 :(得分:1)

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

答案 2 :(得分:1)

<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";
}

答案 3 :(得分:0)

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

检查页面是否获得GET / Post Request。 Read about Get / Post Methods