【发布时间】:2017-05-28 20:34:48
【问题描述】:
跟进这个问题:Save database row id in session for use later
我现在遇到了以下问题。会话现在(谢天谢地)已存储。并且下一页的内容是动态填充的。但是所有页面都有相同的database id,而不是特定于该链接/项目的 id。
我读到一些关于我一遍又一遍地写会话 ID 的事实。我需要将会话存储在一个数组中。
所以我做了以下,我改变了这个:
$identi = $row['Id'];
$_SESSION["product_id"] = $identi;
进入这个:
$identi = $row['Id'];
if(!is_array($_SESSION['product_id'])) {
$_SESSION['product_id']=array();
}
$_SESSION['product_id']=$row['Id'];;
但这仍然只存储会话中最后一个项目的 ID,而不是单个项目。所以我可以让每个项目链接到一个特定的 ID。
为了更好地衡量我的 SQL 查询:
<?php $sql = "SELECT * FROM assortiment WHERE Categorie = '$productid' ORDER BY Id DESC ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<a href='/dbtest/dinner/amsterdam/".$row["Slug"]. "/" . $row["Id"] . "'><div class='products'><div class='col-sm-3'><div class='product-img'>";
$identi = $row['Id'];
if(!is_array($_SESSION['product_id'])) {
$_SESSION['product_id'] = array();
}
$_SESSION['product_id'] = $row['Id'];;
echo "<img src='http://www.example.nl/Uploaded_files/Thumbs/" .$row['Fotomateriaal']. ".jpg'>";
echo "</div></div><div class='col-sm-6'>";
echo "<div class='h2-container'><h2>" . $row["Product"]. "</h2></div>" . $row["Samenvatting"]. "";
echo "</div><div class='col-sm-3'><div class='col-sm-12 text-right'>
<div class='border'>
<p style='margin-bottom:20px;width:30px;'><i class='fa fa-heart' aria-hidden='true'></i></p>
</div>
</div>";
echo "<table>
<tr>
<td><i class='fa fa-users' aria-hidden='true'></i></td>
<td><p>vanaf 10 personen</p></td>
</tr>
<tr>
<td><i class='fa fa-clock-o' aria-hidden='true'></i></td>
<td>" . $row["Tijdsduur"] . " uur</td>
</tr>
<tr>
<td><i class='fa fa-euro' aria-hidden='true'></i></td>
<td>vanaf " . $row["VerkoopPP40"] ." p.p. <small>excl btw</small></td>
</tr>
</table></div></div></a>";
if(isset($_SESSION['product_id'])){
echo $_SESSION['product_id'];
};
}
} else {
echo "0 results";
}?>
有人可以帮我解决这个问题吗?一如既往地提前感谢您的帮助。
【问题讨论】: