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