点击链接

时间:2015-06-21 23:25:20

标签: arrays post hyperlink get

我有4个链接:

<a href=""><img src="img/photo1.jpg" /></a>
<a href=""><img src="img/photo2.jpg" /></a>
<a href=""><img src="img/photo3.jpg" /></a>
<a href=""><img src="img/photo4.jpg" /></a>

我也有md数组:

$users = [
        "id_1" => [
                    "personal_id" => "111111",
                    "name" => "Arthur Novickov",
                    "location" => "Moskow",
                    "age" => "22",
                    "status" => "online"
                    ],
        "id_2" => [
                    "personal_id" => "222222",
                    "name" => "Zack Snyder",
                    "location" => "New York",
                    "age" => "21",
                    "status" => "offline"
                    ],
        "id_3" => [
                    "personal_id" => "333333",
                    "name" => "Anthony Briggs",
                    "location" => "Louisiana",
                    "age" => "36",
                    "status" => "offline"
                    ],
        "id_4" => [
                    "personal_id" => "444444",
                    "name" => "Anne Telma Louise",
                    "location" => "London",
                    "age" => "19",
                    "status" => "online"
                    ],
            ];

毕竟,我需要在点击其中一个链接时显示有关用户的信息。但是(!)我不知道,如何让脚本知道,哪一个被点击了。 我想,可能是提前准备这个信息的可见性:无,然后在点击时设置一个事件。但这听起来很愚蠢,因为可以有50个链接。

这里是信息披露的代码,如果是smth:

function show_info($person) {
                switch ($person) {
                    case '1':
                        echo $users["id_1"]["personal_id"];
                        echo $users["id_1"]["name"];
                        echo $users["id_1"]["location"];
                        echo $users["id_1"]["age"];
                        echo $users["id_1"]["status"];
                        break;
                    case '2':
                        echo $users["id_2"]["personal_id"];
                        echo $users["id_2"]["name"];
                        echo $users["id_2"]["location"];
                        echo $users["id_2"]["age"];
                        echo $users["id_2"]["status"];
                        break;
                    case '3':
                        echo $users["id_3"]["personal_id"];
                        echo $users["id_3"]["name"];
                        echo $users["id_3"]["location"];
                        echo $users["id_3"]["age"];
                        echo $users["id_3"]["status"];
                        break;
                    case '4':
                        echo $users["id_4"]["personal_id"];
                        echo $users["id_4"]["name"];
                        echo $users["id_4"]["location"];
                        echo $users["id_4"]["age"];
                        echo $users["id_4"]["status"];
                        break;              
                    default:
                        break;
                }
            }

1 个答案:

答案 0 :(得分:0)

我猜你正在尝试使用链接到用PHP编码的页面。

在这种情况下,在href属性中添加脚本名称并包含querystring参数将传递信息。

<a href="page.php?person=4"><img src="img/photo4.jpg" /></a>

<?php

if (isset($_GET['person'])) {
    show_info($_GET['person']);
} 

function show_info($person) {
    global $users;
    if (isset($users['id_'.$person])) {
        $user = $users['id_'.$person];
        echo $user["personal_id"];
        echo $user["name"];
        echo $user["location"];
        echo $user["age"];
        echo $user["status"];
    }
}