Php 如何根据href id显示用户json数据库?

Php 如何根据href id显示用户json数据库?,php,json,Php,Json,我将Json数据存储在我的本地主文件夹中,如果我右键单击查看用户数据,我想将用户数据显示到另一个页面“view.php”中。href=“view.php?id=1”用户id=1将自动显示在view.php文件中 data.json { "UserData": [ { "id": "1", "fname": "Joey", "lname": "Tulang", "age": "29", "gender

我将Json数据存储在我的本地主文件夹中,如果我右键单击查看用户数据,我想将用户数据显示到另一个页面“view.php”中。href=“view.php?id=1”用户id=1将自动显示在view.php文件中

data.json

{
    "UserData": [

    {
        "id": "1",
        "fname": "Joey",
        "lname": "Tulang",
        "age": "29",
        "gender": "Male"
    },
    {
        "id": "2",
        "fname": "Angelica",
        "lname": "Bacle",
        "age": "20",
        "gender": "Female"
    },
    {
        "id": "3",
        "fname": "Mj",
        "lname": "King",
        "age": "21",
        "gender": "male"
    }       

    ]   
}
index.php

$jsondata = file_get_contents("data.json");
$json = json_decode($jsondata, true);
$output = "<ul>";

  foreach ( $json['UserData'] as $display ) {

    $output .="<li>" .$display['fname']. " <a href='view.php?".$display['id']."'>View User Data</a></li> </br>";

  }

  $output .= "</ul>";

  echo $output;
$jsondata=file_get_contents(“data.json”);
$json=json_decode($jsondata,true);
$output=“
    ”; foreach($json['UserData']作为$display){ $output.=“
  • ”$display['fname']。“

  • ”; } $output.=“
”; echo$输出;
输出:

view.php

<!DOCTYPE html>
<html>
<head>
    <title>View User Data</title>
</head>
<body>

    <!-- Display User Data Here -->

    <p>First Name: </p>
    <p>Last Name: </p>
    <p>Age: </p>
    <p>Gender: </p>

</body>
</html>

查看用户数据
名字:

姓氏:

年龄:

性别:


index.php

您忘记了
id
param,只是设置了数字

$jsondata = file_get_contents("data.json");
$json = json_decode($jsondata, true);
$output = "<ul>";

foreach ( $json['UserData'] as $display ) {
  $output .="<li>" .$display['fname']. " <a href='view.php?id=".$display['id']."'>View User Data</a></li> </br>";
}

$output .= "</ul>";

echo $output;

index.php

您忘记了
id
param,只是设置了数字

$jsondata = file_get_contents("data.json");
$json = json_decode($jsondata, true);
$output = "<ul>";

foreach ( $json['UserData'] as $display ) {
  $output .="<li>" .$display['fname']. " <a href='view.php?id=".$display['id']."'>View User Data</a></li> </br>";
}

$output .= "</ul>";

echo $output;

我忘了提到,最好使用数据库。np,happy codingHi Lawrence你能帮我解决这个问题吗?对不起,我是一个编程新手,我忘了提到,最好使用数据库。np,happy codingHi Lawrence你能帮我解决这个问题吗?对不起,我是个编程新手