我有一个显示数组数据的页面。当用户点击其中一个显示的图片时,我需要保存值$ row [“Rif”],因为我需要在另一个页面中显示项目详细信息。
我环顾四周,但似乎Jquery,Ajax是唯一可用的解决方案,但我不知道这些。
有没有办法只使用PHP实现它?
谢谢!
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div class='col-md-3 col-sm-6 col-xs-12'>
<div class='property-container'>
<div class='property-image'>
<img src='img/img02.jpg' alt='test theme'>
<div class='property-price'>
" . $row["DescCom"] . "<br>
<span>" . "€ ". $row["Pre"] . " </span>
</div>
<div class='property-status'>
<span>" . $row["Rif"] . "</span>
</div>
</div>
<div class='property-features'>
<span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
<span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
<span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
</div>
<div class='property-content'>
<h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
<button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
</div>
</div>
</div>";
}
} else {
echo '0 results';
}
$conn->close();
?>
答案 0 :(得分:1)
假设数据存储在$row["Rif"]
<?php
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<div class='col-md-3 col-sm-6 col-xs-12'>
<div class='property-container'>
<div class='property-image'>
// if this is the image you can hyper-link it to next page that will carry the id as well.
<a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>
<div class='property-price'>
" . $row["DescCom"] . "<br>
<span>" . "€ ". $row["Pre"] . " </span>
</div>
<div class='property-status'>
<span>" . $row["Rif"] . "</span>
</div>
</div>
<div class='property-features'>
<span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
<span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
<span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
</div>
<div class='property-content'>
<h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
<button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
</div>
</div>
</div>";
}
} else {
echo '0 results';
}
$conn->close();
?>
如果这是图像,您可以将其超链接到下一页,该页面也会带有ID。
<a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>