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

791

I have created certain links using afor loop in PHP.

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

Page will look like

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?

919

Answer

Solution:

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.

274

Answer

Solution:

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'];

People are also looking for solutions to the problem: php - How to Alert the returned data of ajax?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.