我想從每個循環中創建的鏈接傳遞一個PHP變量。從PHP中的foreach循環中創建的鏈接發送變量到另一個頁面
這裏是生成鏈接和可變發送頁面上的代碼:
$xmlDoc = simplexml_load_file("products.xml");
$storeArray = array();
foreach($xmlDoc->product as $Product) {
echo "Name: " . $Product->name . ", ";
echo "Price: " . $Product->price . ", ";
$store = (string)$Product->store;
if (!array_key_exists($store, $storeArray)) {
$storeArray[$store] = "<a href='searchResults.php?storeSearch=<?php echo $store; ?>'>" .
$store . "</a>";
}}
foreach ($storeArray as $store) {
echo $store . "<br>";
}
這裏是接收可變頁面上的代碼: $ searchByStore = $ _GET [「storeSearch」] ; echo「商店搜索變量是:」。 $ searchByStore;
searchByStore變量未被回顯。有什麼建議?
下面是這個網址如何出現在瀏覽器: .../searchResults.php storeSearch =%3C PHP%20echo%20Best%20Buy;%20%3E 而不是通常的方式,這是什麼??? :? .../searchResults.php storeSearch =最佳%20Buy
這裏是XML文件:
<product type="Electronics">
<name> Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>
<product type="Electronics">
<name>Lap top</name>
<price>599.99</price>
<store>Best Buy</store>
</product>
<product type="Hardware">
<name>Hand Saw</name>
<price>99.99</price>
<store>Lowes</store>
</product>
</products>