【问题标题】:PHP - How to show car details on page when link clicked $_GETPHP - 单击链接时如何在页面上显示汽车详细信息 $_GET
【发布时间】:2021-09-17 09:12:06
【问题描述】:

所以我显示了汽车列表,当用户单击链接时,我想显示用户单击的汽车。然后显示汽车规格和图片...

查看文档,获取 API:ducumentation

到目前为止我的代码:它是 php,所以它不能在 Snippet 中运行,但是你看我到目前为止的代码......

<?php
    $id = $_GET['vehicleid'];

    $url = 'https://gw.bilinfo.net/listingapi/api/export';

    // provide your username and password here
    $auth = base64_encode("demo:ocfB6XzF73");

    // create HTTP context with basic auth
    $context = stream_context_create([
        'http' => ['header' => "Authorization: Basic $auth"]
    ]);

    // query for data
    $data = file_get_contents($url, false, $context);
    // $escaped = json_encode($data);
    $escaped = json_decode($data); //, JSON_FORCE_OBJECT

    /*Initializing temp variable to design table dynamically*/
    $temp = "<table class='car-list'>";

    /*Defining table Column headers depending upon JSON records*/
    $temp .= "<tr>";
    $temp .= "<th colspan='4' class='th-style'>Altid mellem 70 og 100 biler i vores udstilling</th>";
    $temp .= "</tr>";
   /*Dynamically generating rows & columns*/
   foreach ($escaped->Vehicles as $vehicle) {
    if($vehicle->vehicleid = $id) {
        $temp .= "<tr>";
        $temp .= "<td class='td-style'>Bil id: " . $vehicle->vehicleid . "</td>";
        $temp .= "<td class='td-style'>Producent: " . $vehicle->Make . "</td>";
        $temp .= "<td class='td-style'>Model: " . $vehicle->Model . "</td>";
        $temp .= "<td class='td-style'>Variant: " . $vehicle->Variant . "</td>";
        $temp .= "</tr>";
        $temp .= "<tr>";
        $temp .= "<td class='td-style'>Pris: " . $vehicle->Price . "</td>";
        $temp .= "<td class='td-style'>Type: " . $vehicle->PriceType . "</td>";
        $temp .= "<td class='td-style'>Kontaktpris: " . $vehicle->CashPrice . "</td>";
        $temp .= "<td class='td-style'>Sælger: " . $vehicle->DealerName . "</td>";
        $temp .= "</tr>";
        $temp .= "<tr>";
        $temp .= "<td class='td-style'>Udsalgspris: " . $vehicle->WholesalePrice . "</td>";
        $temp .= "<td class='td-style pictures'>";
        for ($p = 0; $p < $vehicle->PictureCount; $p++) {
    
            if ($p < 1) {
                $temp .= "<table>";
                $temp .= "<tr>";
                $temp .= "<td rowspan='2' class='td-style'>";
                $temp .= "<img class='cc-images' src='" . $vehicle->Pictures[$p] . "'>";
                $temp .= "</td>";
                $temp .= "</tr>";
                $temp .= "</table>";
            }
        }
        $temp .= "</td>";
        $temp .= "</tr>";
    
     } elseif ($vehicle->vehicleid <> $id) {
         echo $temp .= "No match...";
         break;
     }
    }

    /*End tag of table*/
    $temp .= "</table>";

    /*Printing temp variable which holds table*/
    echo $temp;

    //echo $data;
?>

【问题讨论】:

  • &lt;a href='?vehicleid=" . $vehicle-&gt;VehicleId . "'&gt;,然后$_GET['vehicleid'] 得到它
  • @brombeer 你能写出 $_GET 的标准吗,我是个新手...
  • 您到底遇到了什么问题?创建一个处理显示单个车辆的新 .php 文件可能是个好主意。使用 &lt;a href='vehicle.php?vehicleid=" . $vehicle-&gt;VehicleId . "'&gt;...&lt;/a&gt; 链接到它,然后使用 $_GET['vehicleid'] 从 URL 访问值。不是很喜欢它。 PHP 手册有一个关于$_​GET 变量的页面。
  • __GET[-vehicleid]是第二页,怎么处理
  • 就是这样! @brombeer

标签: php post get


【解决方案1】:

@brombeer 刚刚发布了我的问题的答案:

if($vehicle->VehicleId = $id) 

// 应该是:

if($vehicle->VehicleId == $id) 

一个小错误产生大影响。谢谢@brombeer!

【讨论】:

    猜你喜欢
    • 2013-02-11
    • 2014-12-06
    • 1970-01-01
    • 2016-03-10
    • 2017-06-08
    • 2019-11-09
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多