• 28-07-2022, 09:58:39
    #1
    Arkadaşlar Merhaba;
    limde bir js dosyam var içinde bir html oluşturup sayfama kopyalıyorum
        $(document).on('click', '#addRows', function() {
            count++;
            var htmlRows = '';
            htmlRows += '<tr>';
            htmlRows += '<td><input class="itemRow" type="checkbox"></td>';          
             htmlRows += ' <td>   <select class="form-control" data-trigger name="productName[]" id="productName_'+count+'"  id="choices-single-groups">';
            htmlRows += '<?php ';  
            htmlRows += '$statement = $pdo->prepare("SELECT * FROM tbl_malzeme WHERE DURUM=1 AND STOKTAKIP=1");';
            htmlRows += '$statement->execute();';
            htmlRows += '$result = $statement->fetchAll(PDO::FETCH_ASSOC);   ';                        
            htmlRows += 'foreach ($result as $stoktakip) {     ?>';
            htmlRows += '<option value="<?php echo $stoktakip[MID] ?>"><?php echo $stoktakip[MADI] ?> </option>';
            htmlRows += '<?php } ?>';
            htmlRows += '</select></td> ';          
        
            htmlRows += '<td><input type="number" name="quantity[]" id="quantity_'+count+'" class="form-control quantity" autocomplete="off" required></td>';          
            htmlRows += '<td><input type="number" name="price[]" id="price_'+count+'" class="form-control price" autocomplete="off" required></td>';        
            htmlRows += '<td><input type="number" name="total[]" id="total_'+count+'" class="form-control total" autocomplete="off" required></td>';          
            htmlRows += '</tr>';
            $('#invoiceItem').append(htmlRows);
        });
    bunun içinde php kodları da var. bu htmlRows değişkeni php sayfasına gelirken php tagları yorum satırına donüşüyor.

    neden olabilir yada çözüm yolu nedir acaba
  • 28-07-2022, 10:06:40
    #2
    js dosyasının içinde o kodu çalıştıramazsınız, kodu php dosyanıza taşıyıp script elementinin arasına almayı deneyin. Ayrıca json encode ve ajax konusunda biraz araştırma yapmanızı tavsiye ederim. Stackoverflow ve w3schools üzerinde detaylı bilgi edinebilirsiniz.
  • 28-07-2022, 10:18:05
    #3
    Hocam .js dosyası içinde PHP çalıştıramazsınız ama nasıl olur. PHP dosyanızın içinde <script type="text/javascript" ></script> taglarının içinde PHP taglarını kullanabilirsiniz.
    data: <?= $dataRes; ?>,
    gibi