尝试将 href=""更改为 href='' 时,我在 php 中遇到错误。基本上我有一个代码来输出数据库中列出的产品列表。我想在标题上创建一个链接,如“”,问题是我无法更改 href 以包含变量。我认为这与 php 代码有关,但因为我是 php 的初学者,所以我不知道该怎么做。
代码如下:
$outputList = '';
while($row = mysql_fetch_array($sql2)){
$id = $row["id"];
$title = $row["title"];
$location = $row["location"];
$price = $row["price"];
$description = $row["description"];
$map = $row["map"];
$image = $row["image"];
$outputList .= '<div class="ind_result">
<div class="w-row">
<div class="w-col w-col-3 w-col-small-6 w-clearfix image">
<img class="image" src="'.$image.'">
</div>
<div class="w-col w-col-9 w-col-small-6 w-clearfix desc"><a class="title" href="">' .$title. '</a>
<h4 class="price">'.$price.'</h4>
<h5 class="sub-title">'.$location.'<a href="'.$map.'"><img class="map" src="../images/map.png"></a></h5>
<p class="description">'.$description.'</p>
</div>
</div>
</div>';
我试过使用 echo 而不是 $outputList,但只得到错误。任何帮助,将不胜感激。谢谢
重新编辑: 这是我要实现的代码:
<a class="title" href='example.php?propertyid=$id'>' .$title. '</a>
代替
<a class="title" href="">' .$title. '</a>
最佳答案
href="example.php?propertyid=' .$id. '">' .$title. '</a>
关于php - 使用 php 在 href 中放置变量时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20305958/