2015-08-26 57 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> 
相关问题