• 11-10-2015, 17:30:04
    #1
    Merhaba,

    Ayax ile şehir ve semt seçimi uygulamasını kullandığım bir sitede düzenleme sayfasında şehir geliyor ancak semti nasıl getirebilirim ?

    Kodlar bu şekilde
    	$(function() {
    
    	  $("select[name=il]").change(function() {
    	    var id = $(this).val();
    
    	    if (id != 0) {
    	      $.post("ajax.php", {
    	        "id": id
    	      }, function(sonuc) {
    
    	        $("select[name=ilce]").html(sonuc);
    	      });
    	    }
    	  });
    
    	});
    <div class="control-group">
      <label class="control-label">Şehir</label>
      <div class="controls">
        <select name="il" class="span6 chosen " data-placeholder="Seçiniz" tabindex="1">
          <option value="0">Seçiniz</option>
          <?php $shr=m ysql_query( "select * from il order by il_adi asc"); while($sehir=m ysql_fetch_array($shr)){ ?>
          <option class="minput" value="<?php echo $sehir['il_id']; ?>">
            <?php echo $sehir[ 'il_adi']; ?>
          </option>
          <?php } ?>
        </select>
      </div>
    </div>
    
    
    <div class="control-group">
      <label class="control-label">ilçe</label>
      <div class="controls">
        <select name="ilce" class="span6 chosen" data-placeholder="Seçiniz">
          <option value="0">Önce Şehir Seçiniz</option>
    
        </select>
      </div>
    </div>

    Ajax.php

    <? php
    
    	include("baglanti.php");
    
    	if ($_POST) {
    
    	  echo $id = mysql_real_escape_string($_POST['id']);
    
    	  $bul = mysql_query("select * from ilce where il_id=$id");
    
    	  while ($goster = mysql_fetch_object($bul)) {
    
    	    echo '<option value="'.$goster - > ilce_id.
    	    '">'.$goster - > ilce_adi.
    	    '</option>';
    	  }
    	} ?>
    Birde elinde güncel şehir ve semt sql dosyası olan arkadaşlar paylaşabilirse çok sevinirim..

    İyi çalışmalar
  • 11-10-2015, 21:40:13
    #2
    Merhaba,

    http://www.serpito.com/php-ajax-il-i...me-uygulamasi/
    Veritabanı için Google'a "github il ilçe semt" araması yaparsanız baya bir sonuç gelecektir.