1

I need that when I search something in table, run again PHP script or remove table body inside then incoming AJAX response I will add in table body. How can I do that?

My PHP script like that now:

                    <?php
                    $sql = "SELECT * FROM x_crm INNER JOIN x_crm_kategori ON x_crm.k_id = x_crm_kategori.k_id WHERE durum != 3";
                    if (!empty(re('ara'))) {
                        $ara = re('ara');
                        $sql .= "  and x_crm.unvan LIKE '%".$ara."%' OR x_crm.yetkili LIKE '%".$ara."%' OR x_crm_kategori.k_adi LIKE '%".$ara."%' OR x_crm.butce LIKE '%".$ara."%'";
                    }
                    $sql.=' LIMIT 20';
                    $sorgu = $db->rawQuery($sql);
                    if (!$sorgu) {
                            echo 'Data Not Found';
                    }
                    foreach ($query as $customer) {
                ?>

My tbody in the continuation:

<tr id="tr_<?= $musteri['id'] ?>">
                    <td class="text-center"><?= $musteri['id'] ?></td>
                    <td class="font-w600"><a href="#"><?= $musteri['unvan'] ?></a></td>
                    <td class="hidden-xs font-w600"><?= $musteri['yetkili'] ?></td>
                    <td class="hidden-xs"><?= $musteri['k_adi'] ?></td>
                    <td class="hidden-xs"><?= $musteri['butce'] ?></td>
                    <td>
                        <div class="btn-group hidden-xs">
                            <a href="tel:<?= $musteri['telefon'] ?>"  class="btn btn-sm btn-default" data-toggle="tooltip" title="<?= $musteri['telefon'] ?>" data-original-title="<?= $musteri['telefon'] ?>"><i class="fa fa-phone"></i></a>

                            <a href="mailto:<?= $musteri['eposta'] ?>"  class="btn btn-sm btn-default" data-toggle="tooltip" title="<?= $musteri['eposta'] ?>" data-original-title="<?= $musteri['eposta'] ?>"><i class="fa fa-envelope"></i></a>

                            <a href="<?= $musteri['web'] ?>" target="_blank" class="btn btn-sm btn-default" data-toggle="tooltip" title="<?= $musteri['web'] ?>" data-original-title="<?= $musteri['web'] ?>"><i class="fa fa-link"></i></a>

                            <div class="btn btn-sm btn-default" data-toggle="tooltip" title="MY: <?= $musteri['yetkili'] ?>" data-original-title="MY: <?= $musteri['yetkili'] ?>"><i class="fa fa-user"></i></div>

                            <div class="btn btn-sm btn-warning" data-toggle="tooltip" title="Favori" data-original-title="Favori"><i class="fa fa-star"></i></div>
                        </div>
                    </td>
                    <td class="text-center">
                        <div class="btn-group hidden-xs">
                            <a href="#" data-musteri="<?= $musteri['id'] ?>" class="btn btn-sm btn-default" data-toggle="tooltip" title="Detay" data-original-title="Detay"><i class="fa fa-edit"></i></a>
                            <div class="col-xs-6"><label class="css-input switch switch-sm switch-success">
                                <input id="pasiflik_<?= $musteri['id'] ?>" data-musteri = "<?= $musteri['id'] ?>" type="checkbox" onchange="durumGuncelle(<?= $musteri['id'] ?>)" <?=($musteri['durum']=='1') ? 'checked' : ' ' ?>><span></span></label>
                            </div>
                            <a href="javascript:void(0)" onclick="dataDelete(<?= $musteri['id'] ?>)" data-musteri="<?= $musteri['id'] ?>" class="btn btn-sm btn-default" data-toggle="tooltip" title="Sil" data-original-title="Sil"><i class="fa fa-times"></i></a>
                        </div>
                    </td>
                </tr>
                <?php } ?>

js :

    $('#ara').click(function(){
    var ara_val = $('#icerik_ara').val();
    
    if (ara_val =="") {
        console.log('Boş');
    }else{
        $(location).attr('href', 'https://adresgezginitasarim.com/sistem2021/admin/?modul=crm&sayfa=liste&ara='+ara_val+' ');
    }
})

Sorry for my bad English, thanks in advance... I'm open to ideas.

Amal K
  • 4,359
  • 2
  • 22
  • 44
  • See about sql injection and the importance of prepared and bound queries – Strawberry Jun 18 '21 at 07:20
  • i am using a function for injection but sure – Alper Uluses Jun 18 '21 at 07:44
  • And note that LIMIT without ORDER BY is fairly meaningless – Strawberry Jun 18 '21 at 08:18
  • `i am using a function for injection but sure `...it won't protect you properly. Prepared statements and parameters are the _only_ way to guarantee protection. See [How can I prevent SQL injection in PHP?](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) for the correct way. – ADyson Jun 18 '21 at 08:28
  • Anyway it seems like you know you need AJAX, so...what have you tried? Where are you stuck, specifically? I don't see any kind of AJAX code in your question. What exactly is the issue? – ADyson Jun 18 '21 at 08:30

0 Answers0