所以我正在顯示一個汽車串列,當用戶點擊鏈接時,我想顯示用戶點擊的汽車。然后顯示汽車的規格和圖片。
請看一下API的檔案。教育檔案
到目前為止,我的代碼:它是php,所以它不能在Snippet中運行,但你看我到目前為止的代碼...
。<?php
$id = $_GET['vehicleid'];
$url = 'https://gw.bilinfo.net/listingapi/api/export';
//在這里提供你的用戶名和密碼
$auth = base64_encode("demo:ocfB6XzF73");
//創建帶有基本認證的HTTP背景關系
$context = stream_context_create([
'http' => ['header' => "Authorization: Basic $auth"] 。
]);
// 查詢資料
$data = file_get_contents($url, false, $context);
// $escaped = json_encode($data);
$escaped = json_decode($data); //, JSON_FORCE_OBJECT
/*初始化臨時變數以動態設計表格*//
$temp = "<table class='car-list'> " 。
/*根據JSON記錄定義表的列頭*/。
$temp .= "<tr>";
$temp . = "< th colspan='4'/span> class='th-style'/span>> Altid mellem 70 og 100 biler i vores udstilling</th>/span>"。
$temp .= "</tr>" 。
/*動態生成行& 列 */
foreach ($escaped-> Vehicles as $vehicle) {
如果($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'>/span>Variant: " . $vehicle-> Variant . "</td>" 。
$temp .= "</tr>" 。
$temp .= "<tr>" 。
$temp .= "<td class='td-style'>/span>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'/span>>"。
for ($p = 0; $p < $vehicle-> PictureCount; $p ) {
如果($p < 1) {
$temp .= "<table>" 。
$temp .= "<tr>" 。
$temp . = "< td rowspan='2' class='td-style'>/span>"。
$temp .= "<img class='cc-images' src=' " . $vehicle->圖片[$p] . "'>"。
$temp .= "</td>"。
$temp .= "</tr>" 。
$temp .= "</table>"。
}
}
$temp .= "</td>"。
$temp .= "</tr>"。
} elseif ($vehicle->vehicleid <>/span> $id) {
echo $temp .= "No match...";
休息。
}
}
/*表格的結束標簽*/
$temp .= "</table>/span>"。
/*列印存放表格的臨時變數*/)
echo $temp;
//echo $data;
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
@brombeer剛剛發布了我的問題的答案:
if($vehicle-> VehicleId = $id)
//應該是:
if($vehicle-> VehicleId == $id)
一個影響很大的小錯誤。謝謝@brombeer!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/331335.html
標籤:
