• 19-01-2018, 10:26:08
    #1
    arkadaşlar sql sorgusundan sonra 2 ayrı while fonksiyonu kullanmam gerekiyor. ama her while fonksiyonundan önce ayrı ayrı aynı sql sorgusu yapınca while fonksiyonları başarılı bir şekilde çalışıyor. Sormak istediğim şu. Bunun bir sakıncası var mı? Varsa while ler için tek bir sql sorgusu nasıl yapabilirim. Bu arada Phpde yeniyim.


     
    echo '<form action="" method="post">
    <table class="table">
           <tr><th>Seçiniz</th>
                <td>Seçim 1</td>
                <td>Seçim 2</td></tr><tr>
    <td></td>
    <td><select name="m_tk1">';
    
    $sorgu = $baglanti->query('SELECT id, isim FROM tabloismi where sart = "'.$l_id.'"');
    while ($sonuc = $sorgu->fetch_assoc()) { //while 1 başlangıç
    $id = $sonuc['id'];
    $isim = $sonuc['isim'];
     echo '
     <option value="'.$id.'">'.$isim.'</option>';
    } //while 1 bitiş
    echo "</select></td>";
    echo "<td><select name=\"m_tk2\">";
    $sorgu = $baglanti->query('SELECT id, isim FROM tabloismi where sart = "'.$l_id.'"');
    while ($sonuc = $sorgu->fetch_assoc()) { //while 2 başlangıç
    $id = $sonuc['id'];
    $isim = $sonuc['isim'];
    echo '<option value="'.$id.'">'.$isim.'</option>';
    }  //while 2 bitiş
        echo '</select></td></tr>
        <input type="hidden" name="onceki" value="'.$onceki_id.'" class="form-control" >
             <td></td>
                <td><input class="btn btn-primary"  type="submit" value="İleri"></td>
            
        </table>
    </form>';
    Şimdiden teşekkürler...
  • 19-01-2018, 12:24:36
    #2
    Üyeliği durduruldu
    İki kere sorgu yapıp yormanıza gerek yok.

    <?
    echo '<form action="" method="post">
    <table class="table">
           <tr><th>Seçiniz</th>
                <td>Seçim 1</td>
                <td>Seçim 2</td></tr><tr>
    <td></td>
    <td><select name="m_tk1">';
     
    $sorgu = $baglanti->query('SELECT id, isim FROM tabloismi where sart = "'.$l_id.'"');
    $sonuc = $sorgu->fetch_assoc();
    while ($sonuc) { 
        $id = $sonuc['id'];
        $isim = $sonuc['isim'];
        echo '<option value="'.$id.'">'.$isim.'</option>';
    }
    echo "</select></td>";
    echo "<td><select name=\"m_tk2\">";
    while ($sonuc) {
        $id = $sonuc['id'];
        $isim = $sonuc['isim'];
        echo '<option value="'.$id.'">'.$isim.'</option>';
    }  
        echo '</select></td></tr>
        <input type="hidden" name="onceki" value="'.$onceki_id.'" class="form-control" >
             <td></td>
                <td><input class="btn btn-primary"  type="submit" value="İleri"></td>
             
        </table>
    </form>';
    ?>
  • 19-01-2018, 23:59:40
    #3
    LDestek adlı üyeden alıntı: mesajı görüntüle
    İki kere sorgu yapıp yormanıza gerek yok.

    <? echo '<form action="" method="post"> <table class="table"> <tr><th>Seçiniz</th> <td>Seçim 1</td> <td>Seçim 2</td></tr><tr> <td></td> <td><select name="m_tk1">'; $sorgu = $baglanti->query('SELECT id, isim FROM tabloismi where sart = "'.$l_id.'"'); $sonuc = $sorgu->fetch_assoc(); while ($sonuc) { $id = $sonuc['id']; $isim = $sonuc['isim']; echo '<option value="'.$id.'">'.$isim.'</option>'; } echo "</select></td>"; echo "<td><select name=\"m_tk2\">"; while ($sonuc) { $id = $sonuc['id']; $isim = $sonuc['isim']; echo '<option value="'.$id.'">'.$isim.'</option>'; } echo '</select></td></tr> <input type="hidden" name="onceki" value="'.$onceki_id.'" class="form-control" > <td></td> <td><input class="btn btn-primary" type="submit" value="İleri"></td> </table> </form>'; ?>
    Merhaba. Deneyip Size Döneceğim...