• 01-12-2021, 16:21:57
    #1
    Merhabalar. SQL veritabanından çektiğim verileri toplu olarak değiştirip toplu olarak güncellemek istiyorum. Bu form sonucunu toplufiyatguncellesonuc.php dosyasında SQL de update etmek istiyorum. Kodları aşağıda paylaşıyorum yardımcı olabilir misiniz?

    ayarlar.php dosyası
    $db = new PDO("sqlsrv:Server=**;Database=**", "**", "********");
    Fiyatlar.php dosyası
    <?php require 'ayarlar/ayarlar.php'; ?>
    
    <?php
    if(isset($_GET['modelkodu'])) {
    $modelkodu =  $_GET['modelkodu'];
    $data = $db -> query("
    SELECT
    ITM.LOGICALREF AS ITMID,
    ITM.CODE AS KOD,
    ITM.NAME AS ISIM,
    ITM.STGRPCODE AS GRUP,
    PRC.PRICE AS ESKIFIYAT,
    PRC.CODE AS FIYATKODU,
    UB.BARCODE AS BARKOD,
    PRC.LOGICALREF AS PRCLOGICALREF,
    PRC.TRADINGGRP AS FIYATGRUBU,
    PRC.CAPIBLOCK_MODIFIEDDATE AS DTARIH,
    PRC.CAPIBLOCK_MODIFIEDHOUR AS DSAAT,
    PRC.CAPIBLOCK_MODIFIEDMIN AS DDAKIKA,
    PRC.CAPIBLOCK_MODIFIEDSEC AS DSANIYE,
    PRC.DEFINITION_ AS MTARIH
    
    FROM $prclist PRC
    
    LEFT JOIN $items ITM
    ON PRC.CARDREF = ITM.LOGICALREF
    
    LEFT JOIN $unitbarcode UB
    ON PRC.CARDREF = UB.ITEMREF
          
    WHERE ITM.CODE LIKE '%$modelkodu%' or ITM.NAME LIKE '%$modelkodu%' and ITM.ACTIVE = 0
    ORDER BY ITM.CODE ASC
    ")->fetchAll();
    ?>
    <form action="toplufiyatguncellesonuc.php" method="get" target="_blank">
     <table id="example1" class="table table-bordered table-striped">
    <thead>
    <tr>
        <th>No</th>
        <th>Ürün Kodu</th>
        <th>Ürün Adı</th>
        <th>Maliyet</th>
        <th>Eski Fiyatı</th>
        <th>Yeni Fiyatı</th>
         <th>Fiyat Grubu</th>
        <th>Son Güncelleme Tarihi</th>
        <th>Manuel Güncelleme Tarihi</th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1;?>
    <?php foreach ($data as $item) { ?>
                      <tr>
        <td><?php echo $i;?><input name="id-<?php echo $i;?>" value="<?php echo $i;?>" type="hidden"></td>
        <td><?php echo $item["KOD"]; ?></td>
                        <td><?php echo $item["ISIM"]; ?></td>
        <td>
        $itmid = $item["ITMID"];
        $sql ="
        SELECT  TOP 1 PRICE AS SONSATINALMA
        FROM $stline
        WHERE STOCKREF = '$itmid' AND TRCODE = 1
        ORDER BY DATE_ desc";
        $result = $db->query($sql);
        $row = $db->query($sql)->fetch();
        $eskifiyat = number_format($item["ESKIFIYAT"], 4, ',', '.');
        if ($row) {
        $son_satin_alma = number_format($row["SONSATINALMA"], 4, ',', '.');
        echo $son_satin_alma;
        } else {
        $son_satin_alma = 0;
        }
        ?>
        </td>
        <td>
        <?php echo $eskifiyat; ?>
        </td>
        <td bgcolor="#A3E4D7">
        <?php
        if(isset($_GET['carpan'])) {
        $carpimget = $_GET['carpan'];
        $carpim = "1." . $carpimget;
        //$carpimfiyat = $eskifiyat*$carpim;
        ?>
        <input name="yenifiyat" id="yenifiyat" value="<?php echo $item["ESKIFIYAT"]*$carpim; ?>">
        <input name="fiyatkodu" id="fiyatkodu" value="<?php echo $item["FIYATKODU"]; ?>" type="hidden">
        <input name="urunkodu" id="urunkodu" value="<?php echo $item["KOD"]; ?>" type="hidden">
        <input name="urunadi" id="urunadi" value="<?php echo $item["ISIM"]; ?>" type="hidden">
        <input name="barkod" id="barkod" value="<?php echo $item["BARKOD"]; ?>" type="hidden">
        <input name="fiyatgurubu" id="fiyatgurubu" value="<?php echo $item["FIYATGRUBU"]; ?>" type="hidden">
    
        
        <?php
        }
        ?>
        </strong>
        
        <?php // YENİ LİSTESİ BİTER// ?>
        </td>
        <td><?php echo $item["FIYATGRUBU"]; ?></td>
        <?php
        $tarihi = substr($item["DTARIH"], 0, -12);
        $saati = $item["DSAAT"];
        $dakikasi = $item["DDAKIKA"];
        $saniyesi = $item["DSANIYE"];
        /* 2021-11-11 00:00:00.000 */
        $tarih = $tarihi ." ". $saati .":". $dakikasi .":". $saniyesi;
        ?>
        <td><?php echo $tarih ?></td>
        <td><?php echo $item["MTARIH"]; ?></td>
    
                      </tr>
      <?php $i++;?>
    <?php } ?>
    </tbody>
    <tfoot>
    <tr>
        <th>No</th>
        <th>Ürün Kodu</th>
        <th>Ürün Adı</th>
        <th>Maliyet</th>
        <th>Eski Fiyatı</th>
        <th>Yeni Fiyatı</th>
        <th>Fiyat Grubu</th>
        <th>Son Güncelleme Tarihi</th>
        <th>Manuel Güncelleme Tarihi</th>
    </tr>
    </tfoot>
    </table>
    <button type="submit" class="btn btn-info btn-flat">Güncelle</button>
    </form>
    </div>
    <?php } ?>
  • 01-12-2021, 16:40:47
    #2
    hocam zaten form olduğu için dirkekt verileri toplufiyatguncellesonuc.php dosyasında query ile güncelleyemez misiniz? meraktan soruyorum
  • 01-12-2021, 16:47:34
    #3
    Hocam 1 veri olduğunda güncelleyebiliyorum ama gelen verileri ayrı ayrı update edemedim. Yani şöyle, gelen veri 1 id için güncelleme olduğunda

    $yenifiyat = $_GET['yenifiyat'];
    $fiyatkodu = $_GET['fiyatkodu'];
    .
    .
    .
    $db->prepare($sql)->execute([$yenifiyat, $tarih, $saat, $dakika, $saniye, $now]);
    gibi update edebiliyorum ama formdan ayrı ayrı satırlar için gelen verileri seçtirip döndürüp update edemiyorum.