PHP - link 单击 $_GET 时如何在页面上显示汽车详细信息
PHP - How to show car details on page when link clicked $_GET
所以我显示了一个汽车列表,当用户单击 link 我想显示用户单击的汽车。然后显示汽车规格和图像...
查看文档,对于 API:ducumentation
到目前为止我的代码:它是 php 所以它在代码段中没有 运行,但是你看到我到目前为止的代码...
<?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;
?>
@brombeer 刚刚发布了我的问题的答案:
if($vehicle->VehicleId = $id)
// 应该是:
if($vehicle->VehicleId == $id)
小错误大影响。谢谢@brombeer!
所以我显示了一个汽车列表,当用户单击 link 我想显示用户单击的汽车。然后显示汽车规格和图像...
查看文档,对于 API:ducumentation
到目前为止我的代码:它是 php 所以它在代码段中没有 运行,但是你看到我到目前为止的代码...
<?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;
?>
@brombeer 刚刚发布了我的问题的答案:
if($vehicle->VehicleId = $id)
// 应该是:
if($vehicle->VehicleId == $id)
小错误大影响。谢谢@brombeer!