dousi1097
2017-09-23 16:00
浏览 62
已采纳

Php在while中分配会话数组

I would give the datas in the databases and assign to session as array in PHP. I assign value session in while loop. I was think the session is an array but i looked and i view is not an array. I would want to do create session in the while i give the datas of the databases and give the datas of the databases as array in this session. After use this session with foreach in another page.

Code :

<?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;
    }

}

I tried but i not couldn't.

How can i do this?

Please share code model.

I need your help.

Note : My code is complicated. Pardon me. I hoe you understand.

1条回答 默认 最新

相关推荐 更多相似问题