• 01-04-2023, 20:20:06
    #1
    arkadaşlar merhaba;

    şu şekilde

                <?php 
                $projesayisor=$db->prepare("SELECT proje_id FROM proje where proje_durum = '3'");
                $projesayisor->execute();
                $projesayisi = $projesayisor->rowCount();
                ?>
                <div class="col-xl-2 col-md-6 mb-4">
                    <div class="card border-left-primary shadow h-100 py-2">
                        <div class="card-body">
                            <div class="row no-gutters align-items-center">
                                <div class="col mr-2">
                                    <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Aktif Proje <b>Sayısı</b></div>
                                    <div class="h4 mb-0 font-weight-bold text-gray-800"><?php echo $projesayisi; ?></div>
                                </div>
                                <div class="col-auto">
                                    <i class="fas fa-list fa-2x text-gray-300"></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
    
    
                <?php 
                $proje_biten_sayi_sor=$db->prepare("SELECT proje_id FROM proje WHERE proje_durum='4'");
                $proje_biten_sayi_sor->execute();
                $alinan_say = $proje_biten_sayi_sor->rowCount();
                ?>
                <div class="col-xl-2 col-md-6 mb-4">
                    <div class="card border-left-success shadow h-100 py-2">
                        <div class="card-body">
                            <div class="row no-gutters align-items-center">
                                <div class="col mr-2">
                                    <div class="text-xs font-weight-bold text-success text-uppercase mb-1">Alınan <b>İşler</b> </div>
                                    <div class="h4 mb-0 font-weight-bold text-gray-800">
                                        <?php echo 
                                        $alinan_say; ?></div>
                                    </div>
                                    <div class="col-auto">
                                        <i class="fas fa-calendar-check fa-2x text-gray-300"></i>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

    where ile farklı sonuç almak istediğim 2 sorgu var ama aynı kodlar tekrar yazıyorum bunun yerine kullanabileceğim bir yöntem var mı
  • 01-04-2023, 20:25:33
    #2
    where proje_durum in (etc...)
  • 01-04-2023, 20:28:32
    #3
    beatrax adlı üyeden alıntı: mesajı görüntüle
    where proje_durum in (etc...)
    nasıl yani hocam
  • 01-04-2023, 20:29:31
    #4
    kardeşim in yaparak durumları 4 5 olanları çek içerde de ifle kontrol et bu şekilde 2 defa aynı sorguyu yazmamış olursun işte
  • 01-04-2023, 20:30:30
    #5
    beatrax adlı üyeden alıntı: mesajı görüntüle
    kardeşim in yaparak durumları 4 5 olanları çek içerde de ifle kontrol et bu şekilde 2 defa aynı sorguyu yazmamış olursun işte
    hım tamam teşekkürler
  • 01-04-2023, 20:31:46
    #6
    SQL komutuyla tek sorguda halledebilirsiniz.

    SELECT COUNT(proje_id), proje_durum FROM `proje` WHERE proje_durum = 3 OR proje_durum = 4 GROUP BY proje_durum;
    Çıktısı: