2015-08-26 61 views
-3

在這裏我想通過動態生成的href鏈接圖像將動態變量'$ cost'傳遞給另一個php頁面'onewaytrip_passanger_data.php'。 href鏈接圖像的代碼寫入php標籤 這是我的代碼。但它不工作..我想通過動態href鏈接圖像通過php變量到另一個php頁面

<?php 
    $cost=$row['fare']; 
    echo '<a href="onewaytrip_passenger_data.php?fare="$cost""><img src="images/bookbutton.png" width="85" height="20" /></a>'; 
?> 
+0

請檢查您的報價。 – aldrin27

回答

1

更改此:

echo '<a href="onewaytrip_passenger_data.php?fare=$cost""><img src="images/bookbutton.png" width="85" height="20" /></a>'; 

echo '<a href="onewaytrip_passenger_data.php?fare='.$cost.'"><img src="images/bookbutton.png" width="85" height="20" /></a>'; 
+1

@AnilkumarMT爲了清晰起見。當使用單引號時,PHP不會用字符串中的值替換變量名稱。 – Popnoodles

1

用這個代替:

echo '<a href="onewaytrip_passenger_data.php?fare='.$cost.'"><img src="images/bookbutton.png" width="85" height="20" /></a>'; 
+0

非常感謝你.. –

0
echo "<a href=\"onewaytrip_passenger_data.php?fare=\"$cost\"><img src=\"images/bookbutton.png\" width="85" height="20" /></a>"; 

echo "<a href=\"onewaytrip_passenger_data.php?fare=\"" . $cost . "\"><img src=\"images/bookbutton.png\" width="85" height="20" /></a>"; 
0

總是讓自己迷惑自由。有什麼需要做回聲錨標籤。何時,它可以像這樣完成。 現在,請嘗試。

<?php $cost=$row['fare'];?> 
    <a href="onewaytrip_passenger_data.php?fare=<?echo $cost;"> 
     <img src="images/bookbutton.png" width="85" height="20" /> 
    </a> 
相關問題