• 08-06-2015, 12:09:58
    #1
    Üyeliği durduruldu
    Başlık biraz garip oldu ama resimlerle derdimi anlatmaya çalışayım.

    şöyle bir tablo var;

    adeti yazıp seçerek post işlemini şu şekil yapıyorum.
    <?php
    if($_POST){//to run PHP script on submit
    echo '<h2>ADDED</h2> ';
    
    if(!empty($_POST['check_list']))
     {
    
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['check_list'] as $selected)
     {
     echo "Product : " .$selected."&nbsp;&nbsp;";
     }
        if($_POST['quantity'])
        {
          foreach($_POST['quantity'] as $quantity)
          {
          echo "Quantity : " .$quantity."</br>";
          }
        }
      
     }
    
    }
    ?>
    çıktıyı şu şekil veriyor.

    2 tane ürün için adet girerek seçim yapmama rağmen. böyle bir cıktı alıyorum.
    KO1635 üründen 1 tane, KO1798 üründen 2 tane alıp post ettiğimde şöyle bir çıktı ya ihtiyacım var;
    Product : KO1635
    Quantity: 1
    Product : KO1798
    Quantity: 2

    ( checkbox'un value'sundan product geliyor, quantity inputtan adet geliyor )
    yardımcı olabilirseniz sevinirim arkadaşlar.
  • 08-06-2015, 12:24:25
    #2
    Eğer checkbox sayısı input sayısına eşitse ve checkbox name ve input name değerleri örneğin
    <input type="checkbox" name="checkbox[]">
    <input type="checkbox" name="quanity[]">
    şeklinde ise
    <?php
    if($_POST){//to run PHP script on submit
    $qua = $_POST['quantity'];
    
    echo '<h2>ADDED</h2> ';
    
    if(!empty($_POST['check_list']))
     {
    $i=0;
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['check_list'] as $selected)
     {
     echo "Product : " .$selected."&nbsp;&nbsp;\n";
     if(isset($qua[$i])) echo "Quanity:  ".$qua[$i]."\n";
    $i++;
     }  
     }
    
    }
    ?>
  • 08-06-2015, 13:09:12
    #3
    Üyeliği durduruldu
    Kaplan adlı üyeden alıntı: mesajı görüntüle
    Eğer checkbox sayısı input sayısına eşitse ve checkbox name ve input name değerleri örneğin
    <input type="checkbox" name="checkbox[]">
    <input type="checkbox" name="quanity[]">
    şeklinde ise
    <?php
    if($_POST){//to run PHP script on submit
    $qua = $_POST['quantity'];
    
    echo '<h2>ADDED</h2> ';
    
    if(!empty($_POST['check_list']))
     {
    $i=0;
    // Loop to store and display values of individual checked checkbox.
    foreach($_POST['check_list'] as $selected)
     {
     echo "Product : " .$selected."&nbsp;&nbsp;\n";
     if(isset($qua[$i])) echo "Quanity:  ".$qua[$i]."\n";
    $i++;
     }  
     }
    
    }
    ?>
    aynen öyle hocam. peki id, product, quantity adlı 3 kolonum olduğumu farzederek ayrı ayrı db ye nasıl insert edebiliriz.
  • 08-06-2015, 13:16:31
    #4
    Quismo adlı üyeden alıntı: mesajı görüntüle
    aynen öyle hocam. peki id, product, quantity adlı 3 kolonum olduğumu farzederek ayrı ayrı db ye nasıl insert edebiliriz.
    Eğer id alacaksan bence name değerine id'yi ver.
    yani
    <input type="checkbox" name="checkbox[$urun_id]">
    <input type="text" name="quanity[$urun_id]">
    olsun.
    <?php 
    if($_POST){//to run PHP script on submit 
    $qua = $_POST['quantity']; 
    $cl= $_POST['check_list']; 
    
    echo '<h2>ADDED</h2> '; 
    
    if(!empty($cl)) 
     { 
    
    // Loop to store and display values of individual checked checkbox. 
    foreach($cl as $id=>$selected) 
     { 
     echo "ID: " .$id."&nbsp;&nbsp;\n"; 
     echo "Product : " .$selected."&nbsp;&nbsp;\n"; 
     if(isset($qua[$id])) echo "Quanity:  ".$qua[$id]."\n";
    @mysql_query("update tablo set quanity = '".$qua[$id]."' where id='$id'"); 
    
     }   
     } 
    
    } 
    ?>
  • 08-06-2015, 13:20:46
    #5
    Üyeliği durduruldu
    Kaplan adlı üyeden alıntı: mesajı görüntüle
    Eğer id alacaksan bence name değerine id'yi ver.
    yani
    <input type="checkbox" name="checkbox[$urun_id]">
    <input type="text" name="quanity[$urun_id]">
    olsun.
    <?php 
    if($_POST){//to run PHP script on submit 
    $qua = $_POST['quantity']; 
    $cl= $_POST['check_list']; 
    
    echo '<h2>ADDED</h2> '; 
    
    if(!empty($cl)) 
     { 
    
    // Loop to store and display values of individual checked checkbox. 
    foreach($cl as $id=>$selected) 
     { 
     echo "ID: " .$id."&nbsp;&nbsp;\n"; 
     echo "Product : " .$selected."&nbsp;&nbsp;\n"; 
     if(isset($qua[$id])) echo "Quanity:  ".$qua[$id]."\n";
    @mysql_query("update tablo set quanity = '".$qua[$id]."' where id='$id'"); 
    
     }   
     } 
    
    } 
    ?>
    evet şimdi daha iyi anlaşıldı. teşekkür ederim fikir ve yardımınız için.
  • 08-06-2015, 13:23:03
    #6
    Rica ederim.