开发者

How to know whether i have clicked the particular link in the next page

开发者 https://www.devze.com 2023-02-16 09:49 出处:网络
I have created certain links using a for loop in PHP. foreach($storage as $val) { if($val!=\"\") { echo \"$val\";

I have created certain links using a for loop in PHP.

foreach($storage as $val)
{
    if($val!="")
    {
        echo "$val";
        echo "<a href=\"b.html\">Link</a>";
    }
}

Page will look lik开发者_开发知识库e

content1      Link to b.html
content2      Link to b.html
content3      Link to b.html
content4      Link to b.html
...
...

In the next page I want to retrieve the correct content based on the link clicked. Example: If I click the second link the content to be retrieved is "content2".

How can I accomplish this?


Create your links like that:

echo '<a href="b.html?content=' . $val . '">Link</a>'

Then, on the other page, use this code:

$content = isset($_GET['content']) ? $_GET['content'] : '';

Then $content contains whatever was passed in the URL - or an empty string if the param was missing.


You could set Get parameters so that your links are to b.html?var=content2

Then you can just read the Get Parameters

 echo $val ."<a href=\"b.html?var=". $val ."\">Link</a>";

and you can then view this value with

echo $_GET['var'];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号