<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bilgisayar &#187; json</title>
	<atom:link href="https://www.bilgisayar.me/index.php/tag/json/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bilgisayar.me</link>
	<description></description>
	<lastBuildDate>Wed, 29 Aug 2018 20:31:06 +0000</lastBuildDate>
	<language>tr-TR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.29</generator>
	<item>
		<title>PHP, AJAX ve json_encode kullanarak veritabanı tablo verilerini HTML etiketinde gösterme</title>
		<link>https://www.bilgisayar.me/index.php/2015/07/24/php-ajax-ve-json_encode-kullanarak-veritabani-tablo-verilerini-html-etiketinde-gosterme/</link>
		<comments>https://www.bilgisayar.me/index.php/2015/07/24/php-ajax-ve-json_encode-kullanarak-veritabani-tablo-verilerini-html-etiketinde-gosterme/#comments</comments>
		<pubDate>Fri, 24 Jul 2015 22:09:22 +0000</pubDate>
		<dc:creator><![CDATA[Hakan Atılgan]]></dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.bilgisayar.me/?p=1266</guid>
		<description><![CDATA[PHP, AJAX ve json_encode kullanarak veritabanı tablo verilerini UL etiketinde gösterme]]></description>
				<content:encoded><![CDATA[<p>İlk önce bir veritabanı tablosu oluşturalım.</p>
<pre class="prettyprint linenums" >
CREATE TABLE IF NOT EXISTS `musteri` (
  `no` int(11) NOT NULL,
  `musteri_isim` varchar(50) DEFAULT NULL,
  `sehir` varchar(50) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
</pre>
<p>Oluşturduğumuz tabloyu güncelleyelim</p>
<pre class="prettyprint linenums" >
INSERT INTO `musteri` (`no`, `musteri_isim`, `sehir`) VALUES
(1, &#039;Hakan Atilgan&#039;, &#039;İstanbul&#039;),
(2, &#039;Murat Yalçın&#039;, &#039;Çorum&#039;),
(3, &#039;Süleyman Solak&#039;, &#039;Burdur&#039;),
(4, &#039;Emine Gürel&#039;, &#039;Sivas&#039;),
(5, &#039;Mustafa Doğan&#039;, &#039;İzmir&#039;);
</pre>
<p>ajax.php sayfasi oluşturalım. Oluşturduğumuz sayfada veritabanımıza bağlanalım ve verilerimizi json_encode PHP işlevi ile HTML sayfamıza göndermek için hazıe hale getirelim.</p>
<pre class="prettyprint linenums" >
&lt;?php
$host=&quot;localhost&quot;; // yerel bilgisayar için &#039;localhost&#039; veya &#039;127.0.0.1&#039;
$kullaniciadi=&quot;Veritabanı kullanici adı&quot;;
$sifre=&quot;Veritabanı şifresi&quot;;
$veritabani= &quot;Veritabanı ismi&quot;;

/* Veritabanı bağlantı parametreleri ile yeni bir mysqli nesnesi oluştur */
$mysqli = new mysqli($host, $kullaniciadi, $sifre, $veritabani);
if(mysqli_connect_errno()) {
    echo &quot;Hata oluştu: &quot; . mysqli_connect_errno();
    exit();
}
$sql = &quot;SELECT * FROM musteri&quot;;
$sonuc = $mysqli-&gt;query($sql);
$rows = array();
while($r = $sonuc-&gt;fetch_assoc()) {
    $rows[] = $r;
}
print json_encode($rows);
?&gt;
</pre>
<p>Yukarıdaki PHP kodu çalıştığında aşağıdaki gibi olacaktır.</p>
<pre class="prettyprint linenums" >
[{&quot;no&quot;:&quot;1&quot;,&quot;musteri_isim&quot;:&quot;Hakan Atilgan&quot;,&quot;sehir&quot;:&quot;\u0130stanbul&quot;},{&quot;no&quot;:&quot;2&quot;,&quot;musteri_isim&quot;:&quot;Murat Yal\u00e7\u0131n&quot;,&quot;sehir&quot;:&quot;\u00c7orum&quot;},{&quot;no&quot;:&quot;3&quot;,&quot;musteri_isim&quot;:&quot;S\u00fcleyman Solak&quot;,&quot;sehir&quot;:&quot;Burdur&quot;},{&quot;no&quot;:&quot;4&quot;,&quot;musteri_isim&quot;:&quot;Emine G\u00fcrel&quot;,&quot;sehir&quot;:&quot;Sivas&quot;},{&quot;no&quot;:&quot;5&quot;,&quot;musteri_isim&quot;:&quot;Mustafa Do\u011fan&quot;,&quot;sehir&quot;:&quot;\u0130zmir&quot;}] 
</pre>
<p>index.php sayfamızı oluşturalım ve aşağıdaki html kodunu kopyalayıp yapıştıralım.</p>
<pre class="prettyprint linenums" >
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Bilgisayar.me&lt;/title&gt;
&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;ul&gt;&lt;/ul&gt;

&lt;script type=&#039;text/javascript&#039;&gt;
$(document).ready(function(){
    $.getJSON(&#039;ajax.php&#039;, function(data) {
        $.each(data, function(no, deger) {
            $(&#039;ul&#039;).append(&#039;&lt;li id=&quot;&#039; + no+ &#039;&quot;&gt;&#039; + deger.musteri_isim + &#039; - &#039; + deger.sehir + &#039;&lt;/li&gt;&#039;);
        });
    });
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>index.php sayfasını çalıştırdığımızda aşağıdaki gibi bir liste elde oluruz.</p>
<ul>
<li>Hakan Atilgan &#8211; İstanbul</li>
<li>Murat Yalçın &#8211; Çorum</li>
<li>Süleyman Solak &#8211; Burdur</li>
<li>Emine Gürel &#8211; Sivas</li>
<li>Mustafa Doğan &#8211; İzmir</li>
</ul>
<p>Dosyaları <a href="https://app.box.com/s/r002q0b6ks35izg3mv8y0hh80egeutnt" target="_blank">buradan</a> yükleyebilirsiniz.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.bilgisayar.me/index.php/2015/07/24/php-ajax-ve-json_encode-kullanarak-veritabani-tablo-verilerini-html-etiketinde-gosterme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
