• 22-11-2019, 12:55:31
    #1
    Arkadaşlar merhaba sepetteki ürünlerin toplam fiyatını nasıl yazdırabilirim? Şimdiden teşekkürler.
     <?php
    $query = $db->prepare("SELECT * FROM siparis_detay INNER JOIN urun ON siparis_detay.urun_id = urun.urun_id WHERE siparis_detay.siparis_id = ?");
    $query->execute(array($_GET['siparis_id']));
    $listele = $query->fetchAll(PDO::FETCH_ASSOC);
    ?>
    <?php foreach($listele as $urunler):?>
    <tr>
    <td><form><input type="checkbox"></form></td>
    <td><img src="imagesdemo-img.jpg" width="100" alt=""></td>
    <td><?php echo $urunler['urun_ad'] ?></td>
    <td><?php echo $urunler['urun_id'] ?></td>
    <td><form><input type="text" class="form-control quantity" value="<?php echo $urunler['urun_adet'] ?>"></form></td>
    <td><?php echo $urunler['urun_fiyat'] ?></td>
    </tr>
    <?php endforeach;?>
  • 22-11-2019, 12:57:35
    #2
     <?php
    $query = $db->prepare("SELECT * FROM siparis_detay INNER JOIN urun ON siparis_detay.urun_id = urun.urun_id WHERE siparis_detay.siparis_id = ?");
    $query->execute(array($_GET['siparis_id']));
    $listele = $query->fetchAll(PDO::FETCH_ASSOC);
    ?>
    <?php
    $toplam=0;
    foreach($listele as $urunler):
    $toplam += $urunler['urun_fiyat'];
    ?>
    <tr>
    <td><form><input type="checkbox"></form></td>
    <td><img src="imagesdemo-img.jpg" width="100" alt=""></td>
    <td><?php echo $urunler['urun_ad'] ?></td>
    <td><?php echo $urunler['urun_id'] ?></td>
    <td><form><input type="text" class="form-control quantity" value="<?php echo $urunler['urun_adet'] ?>"></form></td>
    <td><?php echo $urunler['urun_fiyat'] ?></td>
    </tr>
    <?php endforeach;?>
    <?php echo 'Toplam:' . $toplam
    Şeklinde yazdırabilirsiniz
  • 22-11-2019, 12:58:49
    #3
    $topla[] = $urunler['urun_fiyat'];

    Bunu foreach içinde en üste ekle hocam.

    Foreach dışında da

    array_sum($topla); şeklinde kullanabilirsin.
  • 22-11-2019, 14:42:57
    #4
    Teşekkürler hocam