我會給數據庫中的數據並分配給會話作爲PHP中的數組。我在while循環中分配值會話。我認爲會議是一個數組,但我看,我認爲不是一個數組。我希望在創建會話的同時給出數據庫的數據,並在此會話中以數組形式給出數據庫的數據。在另一個頁面中使用此會話與foreach後。PHP分配會話數組while
代碼:
<?php
$vericek15 = $baglanti10 -> prepare("select * from sepet where kulad = :kulad");
$vericek15 -> bindParam(':kulad', $kulad8);
$vericek15 -> execute();
$vericek16 = $baglanti10 -> prepare("select * from sepet where kulad = ?");
$vericek16 -> bindParam(1, $kulad8);
$vericek16 -> execute();
$vericek16say = $vericek16 -> rowCount();
if ($vericek16say == 0) {
?>
<div id="surunyokl">
<label>Your cart is empty</label>
</div>
<style type="text/css">
#surunyokl{
position: absolute;
top: 325px;
left: 625px;
}
</style>
<?php
} else {
?>
<div id="sepettablo">
<table>
<tr>
<th style="text-align: center;">Image of product</th>
<th style="text-align: center;">Product</th>
<th style="text-align: center;">Piece</th>
<th style="text-align: center;">Price</th>
<th style="text-align: center;">Delete</th>
</tr>
<?php
while($bilgiler15 = $vericek15 -> fetch(PDO::FETCH_ASSOC)){
$vericek17 = $baglanti10 -> prepare("select * from urunlist where urunad = :urunad");
$vericek17 -> bindParam(':urunad', $bilgiler15['urunad']);
$vericek17 -> execute();
$vericek18 = $baglanti10 -> prepare("select * from urunlistresim where urunad = :urunad2");
$vericek18 -> bindParam(':urunad2', $bilgiler15['urunad']);
$vericek18 -> execute();
$bilgi18 = $vericek18 -> fetch();
while($bilgiler17 = $vericek17 -> fetch(PDO::FETCH_ASSOC)){
$_SESSION['b'] = $bilgiler15['urunad'];
$_SESSION['urunadi'] = $bilgiler15['urunad'];
$_SESSION['urunadet'] = $bilgiler15['urunadet'];
$_SESSION['urunfiyat'] = $bilgiler17['urunfiyat'];
if ($bilgiler17['urunadet'] == 0) {
}
echo '<tr>';
echo '<td><img src="'.$bilgi18['resimyol'].'" height="100" width="100"></td>';
echo '<td style="width:500px;text-align:center;">'.$bilgiler15['urunad'].'</td>';
if ($bilgiler17['urunadet'] == 0) {
echo '<td style="width:125px;text-align:center;"><input type="button" value="-" onclick="azalt('.$bilgiler15['no'].');">'.$bilgiler15['urunadet'].'</td>';
}else {
echo '<td style="width:125px;text-align:center;"><input type="button" value="-" onclick="azalt('.$bilgiler15['no'].');">'.$bilgiler15['urunadet'].'<input type="button" value="+" onclick="artir('.$bilgiler15['no'].');"></td>';
}
echo '<td style="width:75px;text-align:center;">'.$bilgiler17['urunfiyat'].'<label><b> € </b></label></td>';
echo '<td><input type="button" value="Delete" onclick="sil('.$bilgiler15['no'].')"></td>';
echo '</tr>';
@$fiyat += $bilgiler17['urunfiyat'] * $bilgiler15['urunadet'];
@$toplamadet += $bilgiler15['urunadet'];
if ($toplamadet == 1) {
$kargo = 5;
}elseif ($toplamadet > 1) {
$kargo = 5 + ($toplamadet - 1);
}else{
}
$toplam = $fiyat + $kargo;
}
}
我試過,但我不是不能。
我該怎麼做?
請分享代碼模型。
我需要你的幫助。
注意:我的代碼很複雜。對不起。我鋤頭你明白。
我們展示的代碼使用的是請 – RiggsFolly
@RiggsFolly確定。 – Thiers
PHP $ _SESSION變量是一個數組,除非你已經做了一些事情來損壞你的代碼 – RiggsFolly