<?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>JQuery, PHP, html, design... // arnaud-k : un blog de geek &#187; PHP</title>
	<atom:link href="http://blog.arnaud-k.fr/category/developpement-web/cat-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arnaud-k.fr</link>
	<description>Le blog JQuery, Html, Web Design</description>
	<lastBuildDate>Thu, 21 Apr 2011 08:10:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Tutorial JQuery : formulaire de recherche en Ajax</title>
		<link>http://blog.arnaud-k.fr/2010/09/14/tutorial-jquery-formulaire-de-recherche-en-ajax/</link>
		<comments>http://blog.arnaud-k.fr/2010/09/14/tutorial-jquery-formulaire-de-recherche-en-ajax/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 11:00:24 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[tutorial JQuery]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1797</guid>
		<description><![CDATA[Chose promis, chose due, voici un tutorial pour faire un formulaire de recherche en Ajax avec JQuery et PHP. Idéal si vous avez envie de copier Google Instant, ce type de formulaire permet de faire gagner du temps à vos&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2010/09/14/tutorial-jquery-formulaire-de-recherche-en-ajax/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2010%2F09%2F14%2Ftutorial-jquery-formulaire-de-recherche-en-ajax%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2010%2F09%2F14%2Ftutorial-jquery-formulaire-de-recherche-en-ajax%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img src="http://blog.arnaud-k.fr/wp-content/uploads/2010/09/ajax-search.jpg" alt="" title="Tutorial JQuery : formulaire de recherche en Ajax" width="600" height="230" class="aligncenter size-full wp-image-1810" /><br />
Chose promis, chose due, voici un tutorial pour faire un <strong>formulaire de recherche en Ajax avec JQuery et PHP</strong>. Idéal si vous avez envie de copier <a href="http://blog.arnaud-k.fr/2010/hors-sujet/autre/google-instant-search-la-recherche-plus-rapide/">Google Instant</a>, ce type de formulaire permet de faire gagner du temps à vos internautes. Et comme on commence à en voir un peu partout (Google, Youtube, Itunes&#8230;), il risque de devenir un standard.</p>
<p>Donc, comme d&#8217;habitude, j&#8217;ai préparé une démo du tutorial :<br />
<a class="demo" title="voir la demo du formulaire de recherche en Ajax" href="http://blog.arnaud-k.fr/demos/jquery-ajax-search/">Demo</a></p>
<p>Et c&#8217;est parti pour le code. On attaque donc par le code HTML de la page. On prépare le formulaire simplement, j&#8217;ai opté pour que l&#8217;on n&#8217;affiche pas le bouton soumission du formulaire. Et on ajoute un bloc vide, celui-ci contiendra les résultats éventuels.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--debut du formulaire--&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;search.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q&quot;</span>&gt;</span>Rechercher un article<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--fin du formulaire--&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--preparation de l'affichage des resultats--&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;results&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Ensuite le gros du code, le code JavaScript utilisant JQuery :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// détection de la saisie dans le champ de recherche</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#q'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $field <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#results'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on vide les resultats</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ajax-loader'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on retire le loader</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// on commence à traiter à partir du 2ème caractère saisie</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> $field.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// on envoie la valeur recherché en GET au fichier de traitement</span>
      $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  	type <span style="color: #339933;">:</span> <span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// envoi des données en GET ou POST</span>
	url <span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax-search.php'</span> <span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// url du fichier de traitement</span>
	data <span style="color: #339933;">:</span> <span style="color: #3366CC;">'q='</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// données à envoyer en  GET ou POST</span>
	beforeSend <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// traitements JS à faire AVANT l'envoi</span>
		$field.<span style="color: #660066;">after</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;img src=&quot;ajax-loader.gif&quot; alt=&quot;loader&quot; id=&quot;ajax-loader&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// ajout d'un loader pour signifier l'action</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	success <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// traitements JS à faire APRES le retour d'ajax-search.php</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ajax-loader'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on enleve le loader</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#results'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// affichage des résultats dans le bloc</span>
	<span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>		
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Et enfin le code du fichier &laquo;&nbsp;ajax-search.php&nbsp;&raquo; effectuant la recherche et le renvoi des éléments :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//connexion à la base de données </span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_de_la_base'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'nom_utilisateur'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mot_de_passe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$link</span>   <span style="color: #339933;">=</span>   <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span> DB_HOST <span style="color: #339933;">,</span> DB_USER <span style="color: #339933;">,</span> DB_PASSWORD <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span> DB_NAME <span style="color: #339933;">,</span> <span style="color: #000088;">$link</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//recherche des résultats dans la base de données</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span>   <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'SELECT post_title , post_date , guid
                          FROM wp_posts
                          WHERE post_status = \'publish\'
                          AND post_title LIKE \''</span> <span style="color: #339933;">.</span> safe<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'%\'
                          LIMIT 0,20'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// affichage d'un message &quot;pas de résultats&quot;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$result</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;h3 style=&quot;text-align:center; margin:10px 0;&quot;&gt;Pas de r&amp;eacute;sultats pour cette recherche&lt;/h3&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// parcours et affichage des résultats</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$result</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;div class=&quot;article-result&quot;&gt;
            &lt;h3&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt; ?php echo utf8_encode( $post-&gt;post_title ); ?&gt;&lt;/a&gt;&lt;/h3&gt;
            &lt;p class=&quot;date&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_date</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
            &lt;p class=&quot;url&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
        &lt;/div&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*****
fonctions
*****/</span>
<span style="color: #000000; font-weight: bold;">function</span> safe<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addcslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Voilà, c&#8217;est tout pour ce tutoriel. Après il peut encore être optimisé en ajoutant des suggestions (toujours à la Google <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Mais on verra ça une autre fois !</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2010/09/14/tutorial-jquery-formulaire-de-recherche-en-ajax/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Un jeu &#171;&#160;Memory&#160;&#187; avec JQuery, PHP et CSS</title>
		<link>http://blog.arnaud-k.fr/2009/09/04/un-jeu-memory-avec-jquery-php-et-css/</link>
		<comments>http://blog.arnaud-k.fr/2009/09/04/un-jeu-memory-avec-jquery-php-et-css/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 11:58:24 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[jeu JQuery]]></category>
		<category><![CDATA[Memory]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1244</guid>
		<description><![CDATA[Pour le dernier article avant le week-end, je te propose de découvrir un jeu fait en JQuery et utilisant le PHP. Le jeu un simple &#171;&#160;Memory&#171;&#160;. Il faut retrouver le plus rapidement possible (et avec le moins de tentatives possibles).&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/09/04/un-jeu-memory-avec-jquery-php-et-css/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F09%2F04%2Fun-jeu-memory-avec-jquery-php-et-css%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F09%2F04%2Fun-jeu-memory-avec-jquery-php-et-css%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-1245" title="jQuery Memotest" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/09/jQuery-Memotest.png" alt="jQuery Memotest" width="533" height="212" /></p>
<p>Pour le dernier article avant le week-end, je te propose de découvrir u<strong>n jeu fait en JQuery et utilisant le PHP</strong>. Le jeu un simple &laquo;&nbsp;<a href="http://www.fernando.com.ar/memo/">Memory</a>&laquo;&nbsp;. Il faut retrouver le plus rapidement possible (et avec le moins de tentatives possibles). Une fois de plus la puissance de JQuery est démontrée, en fait il y a plein de jeux qui peuvent être faits avec JQuery.</p>
<p>C&#8217;est également un bon moyen de faire découvrir JQuery au tout petit ! <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/09/04/un-jeu-memory-avec-jquery-php-et-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Inspiration : Work at Play (web design et JQuery)</title>
		<link>http://blog.arnaud-k.fr/2009/08/17/inspiration-work-at-play-web-design-et-jquery/</link>
		<comments>http://blog.arnaud-k.fr/2009/08/17/inspiration-work-at-play-web-design-et-jquery/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:53:08 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1176</guid>
		<description><![CDATA[Le site de la digital agency work at play m&#8217;a, je dois l&#8217;avouer, assez scotché. Déjà le design avec les photos en fond et (presque) en plein écran et les à-plats de couleur sont très réussis. Les photos simples des&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/08/17/inspiration-work-at-play-web-design-et-jquery/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F17%2Finspiration-work-at-play-web-design-et-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F17%2Finspiration-work-at-play-web-design-et-jquery%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.workatplay.com"><img class="aligncenter size-full wp-image-1177" title="Work at Play" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/08/Work-at-Play.png" alt="Work at Play" width="600" height="310" /></a></p>
<p><strong>Le site de la digital agency <a href="http://www.workatplay.com">work at play</a> m&#8217;a, je dois l&#8217;avouer, assez scotché</strong>. Déjà le design avec les photos en fond et (presque) en plein écran et les à-plats de couleur sont très réussis. Les photos simples des locaux en noir &amp; blanc sont sympas. La charte graphique globale est chaleureuse avec des<strong> couleurs très &laquo;&nbsp;web 2.0&#8243;</strong>.</p>
<p><strong>Autre point positif du site, l&#8217;utilisation de <a href="http://blog.arnaud-k.fr/tag/jquery">JQuery</a> !</strong> Tout le contenu du site est sur la même avec le contenu du site qui slide. J&#8217;ai pu noter l&#8217;utilisation des plugins Draggable (attaché à JQueryUI), Dialog (également compris dans JQueryUI) ou encore <a href="http://lab.smashup.it/flip/">Flip</a> (qui donne un effet de rotation 3d sur un bloc).</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/08/17/inspiration-work-at-play-web-design-et-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recherche à la Twitter avec JQuery et PHP (tutorial)</title>
		<link>http://blog.arnaud-k.fr/2009/08/13/recherche-a-la-twitter-avec-jquery-et-php-tutorial/</link>
		<comments>http://blog.arnaud-k.fr/2009/08/13/recherche-a-la-twitter-avec-jquery-et-php-tutorial/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 09:41:41 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1157</guid>
		<description><![CDATA[Tutorial bien sympa trouvé sur le blog 9lessons : &#171;&#160;Twitter like Search with jQuery and Ajax&#160;&#187; (&#171;&#160;recherche à la twitter avec JQuery et Ajax&#160;&#187;). Ce tuto permet donc de créer un formulaire de recherche tout en Ajax. Les résultats sont&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/08/13/recherche-a-la-twitter-avec-jquery-et-php-tutorial/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F13%2Frecherche-a-la-twitter-avec-jquery-et-php-tutorial%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F13%2Frecherche-a-la-twitter-avec-jquery-et-php-tutorial%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-1158" title="jquery-twitter" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/08/jquery-twitter.png" alt="jquery-twitter" width="600" height="200" /></p>
<p><strong>Tutorial bien sympa trouvé sur le blog 9lessons</strong> : &laquo;&nbsp;<a href="http://9lessons.blogspot.com/2009/08/twitter-like-search-with-jquery-ajax.html">Twitter like Search with jQuery and  Ajax</a>&nbsp;&raquo; (&laquo;&nbsp;recherche à la twitter avec JQuery et Ajax&nbsp;&raquo;). Ce tuto permet donc de créer un formulaire de recherche tout en Ajax. Les résultats sont donc affichés directement sur la même page que le formulaire.</p>
<p>Une démo est disponible directement sur le blog 9lessons.<br />
<a href="http://9lessons.net63.net/newsearch.php" class="demo">Voir la démo</a></p>
<p>A noter que l&#8217;on également <strong>télécharger les scripts expliqués dans le tutorial</strong>. On y retrouve le JQuery, le PHP, l&#8217;HTML et même un peu de CSS. Le tuto est bien complet, l&#8217;effet de recherche en Ajax est toujours classe. J&#8217;espère juste pour toi que tu comprends l&#8217;anglais&#8230; <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/08/13/recherche-a-la-twitter-avec-jquery-et-php-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quelques fonctions PHP utiles (avec PHPfonctions)</title>
		<link>http://blog.arnaud-k.fr/2009/08/12/quelques-fonctions-php-utiles-avec-phpfonctions/</link>
		<comments>http://blog.arnaud-k.fr/2009/08/12/quelques-fonctions-php-utiles-avec-phpfonctions/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 10:13:14 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[bestof]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpfonctions]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=1150</guid>
		<description><![CDATA[Plusieurs mois après la mise en ligne de PHP fonctions, la bibliothèque de fonctions PHP, quelques fonctions PHP se dégagent par leur utilité et leur spécificité. Voici 3 fonctions choisies pour toi : get_last_tweets() par Adrian Gaudebert. Récupère les derniers&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/08/12/quelques-fonctions-php-utiles-avec-phpfonctions/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F12%2Fquelques-fonctions-php-utiles-avec-phpfonctions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F08%2F12%2Fquelques-fonctions-php-utiles-avec-phpfonctions%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-1151" title="phpfonctions-best-of" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/08/phpfonctions-best-of.png" alt="phpfonctions-best-of" width="600" height="200" /></p>
<p>Plusieurs mois après la mise en ligne de PHP fonctions, la bibliothèque de <a href="http://phpfonctions.php">fonctions PHP</a>, quelques fonctions PHP se dégagent par leur utilité et leur spécificité. Voici 3 fonctions choisies pour toi :</p>
<ul>
<li>
<h3><a href="http://phpfonctions.fr/fonction-php.php?fonction=get_last_tweets">get_last_tweets()</a> par <a href="http://adrian.gaudebert.fr/">Adrian Gaudebert</a>.</h3>
<p>Récupère les derniers statuts d&#8217;un compte Twitter. Parfait pour créer un mashup Twitter ou juste afficher ses derniers tweets sur son <a href="http://phpfonctions.fr/fonction-php.php?fonction=getTinyUrl">blog.</a></li>
<li>
<h3><a href="http://phpfonctions.fr/fonction-php.php?fonction=getTinyUrl">getTinyUrl()</a> (par moi-même)</h3>
<p>Permet de raccourcir une URL en utilisant l&#8217;API de Tinyurl. Très utile pour proposer des liens &laquo;&nbsp;partager sur Twitter&nbsp;&raquo; sans dépasser les 140 caractères !</li>
<li>
<h3>La <a href="http://phpfonctions.fr/fonction-php.php?fonction=class%20miniature">Classe Miniature</a> par <a href="http://www.pahtp.com/">PaHtP</a></h3>
<p>Cette classe (malheureusement en PHP 4, mais facilement adaptable à PHP 5) permet de créer la miniature d&#8217;une image avec un redimensionnement proportionnel.</li>
</ul>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/08/12/quelques-fonctions-php-utiles-avec-phpfonctions/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Plugin JQuery : transformer un texte en input ou textarea avec JQuery Editable</title>
		<link>http://blog.arnaud-k.fr/2009/06/18/plugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable/</link>
		<comments>http://blog.arnaud-k.fr/2009/06/18/plugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 10:30:29 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[plugin JQuery]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=745</guid>
		<description><![CDATA[Plugin JQuery que j&#8217;ai découvert hier soir : JQuery Editable. Plugin au concept très simple mais qui, bien utilisé, peut être très pratique. En effet, il permet de remplacer un texte en un champ de saisie (input, select ou textarea)&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/06/18/plugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F18%2Fplugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F18%2Fplugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-746" title="jquery plugin editable" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/06/jquery-editable.png" alt="jquery plugin editable" /></p>
<p>Plugin JQuery que j&#8217;ai découvert hier soir : <a href="http://arashkarimzadeh.com/jquery/7-editable-jquery-plugin.html">JQuery Editable</a>. Plugin au concept très simple mais qui, bien utilisé, peut être très pratique. En effet, il permet de remplacer un texte en un champ de saisie (input, select ou textarea) en cliquant simplement sur le texte à éditer.</p>
<p>Il gère parfaitement les callbacks (fonction à appeler à la fin de l&#8217;execution) à l&#8217;envoi des données (à gérer pourquoi pas en Ajax <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> ). Pratique pour faire de l&#8217;admin d&#8217;un site directement sur le site lui-même (et non pas dans une admin séparée).</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/06/18/plugin-jquery-transformer-un-texte-en-input-ou-textarea-avec-jquery-editable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutoriel : utilisation de Gravatar en PHP</title>
		<link>http://blog.arnaud-k.fr/2009/06/17/tutoriel-utilisation-de-gravatar-en-php/</link>
		<comments>http://blog.arnaud-k.fr/2009/06/17/tutoriel-utilisation-de-gravatar-en-php/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 10:28:51 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[gravatar]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=713</guid>
		<description><![CDATA[Pour le développement d&#8217;un site que j&#8217;ai en cours, j&#8217;ai dû intégrer directement les Gravatars aux membres postant des commentaires. J&#8217;ai été tout bonnement étonné de la simplicité à mettre en place en PHP. Tout ça est en complément de&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/06/17/tutoriel-utilisation-de-gravatar-en-php/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F17%2Ftutoriel-utilisation-de-gravatar-en-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F17%2Ftutoriel-utilisation-de-gravatar-en-php%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Pour le développement d&#8217;un site que j&#8217;ai en cours, j&#8217;ai dû intégrer directement les <a href="http://fr.gravatar.com">Gravatars</a> aux membres postant des commentaires. J&#8217;ai été tout bonnement <strong>étonné de la simplicité à mettre en place en PHP</strong>. Tout ça est en complément de tous les plugins et intégration native sur les CMS et plateformes de blog (Drupal, Joomla, Dotclear ou WordPress).</p>
<p><img class="aligncenter size-full wp-image-714" title="gravatar" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/06/gravatar.png" alt="gravatar" /></p>
<p>Pour rappel, un Gravatar (Globally Recognized Avatar) est <strong>une image qui vous suit sur tous les sites</strong> qui proposent leur intégration. Par exemple sur le blogs WordPress, quand un commentaire est laché, l&#8217;adresse email est demandé et à partir de cet adresse email, Gravatar retourne l&#8217;avatar de l&#8217;utilisateur. C&#8217;est aussi simple que ça.</p>
<p>C&#8217;est parfaitement intégrable sur tous les sites. <strong>Aucune inscription n&#8217;est nécessaire</strong> !</p>
<p>Voici comment le mettre en place en PHP :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;arnaud-k@machin.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// l'adresse email de l'utilisateur</span>
<span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.machin.com/avatar-par-defaut.jpg&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// l'url de l'image à afficher par défaut si l'utilisateur n'a pas de Gravatar</span>
<span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// la taille pour l'affichage du gravatar (celui-ci sera carré)</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on construit ensuite l'url du Gravatar</span>
<span style="color: #000088;">$gravatar</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar.php?gravatar_id=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;amp;default=&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;amp;size=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$size</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p style="margin-top:30px">Il n&#8217;y a plus qu&#8217;à afficher le Gravatar en html :</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php echo $gravatar ?/&gt;</span></span>&quot; alt=&quot;nom du membre&quot; /&gt;</pre></div></div>



<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/06/17/tutoriel-utilisation-de-gravatar-en-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tutorial API Youtube : rechercher et afficher des vidéos (PHP et JQuery)</title>
		<link>http://blog.arnaud-k.fr/2009/06/05/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/</link>
		<comments>http://blog.arnaud-k.fr/2009/06/05/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 11:34:55 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[API youtube]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=623</guid>
		<description><![CDATA[J&#8217;ai eu très récemment l&#8217;occasion de travailler sur l&#8217;API de Youtube. Cette API, évidemment fourni par Google, est très complète et peut permettre beaucoup d&#8217;interactions avec Youtube (recherche et visionnage de vidéos, upload, login, &#8230;). La documentation fourni par Google&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/06/05/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F05%2Ftutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F05%2Ftutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-624" title="Tutoriel API Youtube" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/06/youtube.png" alt="Tutoriel API Youtube" width="600" height="200" /></p>
<p>J&#8217;ai eu très récemment l&#8217;occasion de travailler sur l&#8217;<strong>API de Youtube</strong>. Cette API, évidemment fourni par Google, est très complète et peut permettre beaucoup d&#8217;interactions avec Youtube (recherche et visionnage de vidéos, upload, login, &#8230;). La documentation fourni par Google est, comment dire, un peu fouilli et pas très claire.</p>
<p>Je vais néanmoins te partager mes découvertes en proposant un tutorial pour rechercher des vidéos sur Youtube, afficher les résultats (sous forme de miniature) et lire les vidéos.</p>
<p><a href="http://www.awelty.fr/arnaud-k/youtube/" class="demo" title="Demo Api Youtube">Demo Api Youtube</a></p>
<p>Comme d&#8217;hab, j&#8217;ai préparé une <strong><a href="http://www.awelty.fr/arnaud-k/youtube/">démo de ce tutorial</a></strong> (démo hébergée chez mon employeur car mon hébergement 1&amp;1 n&#8217;est pas PHP 5). Comme c&#8217;est du PHP, j&#8217;ai également prévu le <a href="http://blog.arnaud-k.fr/youtube/APIyoutube.zip">téléchargement</a><strong> des sources de la démo</strong>.</p>
<p>Tout d&#8217;abord il est absolument nécessaire d&#8217;avoir <strong>un serveur PHP 5.2</strong> au minimum. Il faut également télécharger un standalone du framework PHP zend, <a href="http://framework.zend.com/download/gdata">GData</a> qui contient les fichiers nécessaires au fonctionnement de l&#8217;API. Enfin pour juste effectuer des recherches et afficher des vidéos, il n&#8217;est pas nécessaire d&#8217;avoir une key pour l&#8217;API Youtube.</p>
<p>Dans le .zip de GData, il y a un dossier &laquo;&nbsp;librairy&nbsp;&raquo; dans lequel on retrouve un dossier &laquo;&nbsp;Zend&nbsp;&raquo;, c&#8217;est celui-là qu&#8217;il faut uploader à la racine de ton site.</p>
<p><span style="color:#ffa800; font-size:1.3em; font-weight:bold">Jetons maintenant un oeil au code :</span></p>
<p>Le principe est le suivant : on fait une requête (en utlisant les objets mis à disposition par l&#8217;API) et on récupère et on traite les informations à partir du flux XML retourné (<a href="http://code.google.com/intl/fr/apis/youtube/2.0/developers_guide_php.html#Video_Entry_Contents">voir la liste des infos disponible</a>).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Gdata/YouTube.php'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on charge la librairie YouTube</span>
&nbsp;
<span style="color: #000088;">$yt</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on initialise l'objet Youtube</span>
<span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMajorProtocolVersion</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">newVideoQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOrderBy</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'relevance'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// les vidéos sont classées par pertinence</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'all_time'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on souhaite afficher les vidéos qui ont été ajoutées n'importe quand</span>
<span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVideoQuery</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fat freddy's drop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on définit la recherche</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on récupère un flux XML avec la liste des vidéos</span>
<span style="color: #000088;">$flux</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$yt</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVideoFeed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getQueryUrl</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on affiche les miniatures </span>
get_results<span style="color: #009900;">&#40;</span><span style="color: #000088;">$flux</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>La fonction get_results() est une fonction permettant de parcourir le flux XML des résultats pour le traitement des informations. Cette fonction appelle elle-même la fonction afficheMiniature() qui permet d&#8217;afficher les miniatures des vidéos. Ici, je stoppe le listing des résultats à 6, mais on peut en afficher jusqu&#8217;à 25.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/******** FONCTIONS POUR L'API YOUTUBE ********/</span>
<span style="color: #666666; font-style: italic;">// On recupère l'url du player flash et une miniature de la video (format 120*90)</span>
<span style="color: #666666; font-style: italic;">// et on affiche la miniature en mettant l'url du player en id (pour le récupérer avec JQuery après)</span>
<span style="color: #000000; font-weight: bold;">function</span> afficheMiniature<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$miniature</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$video</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getVideoThumbnails</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;img class=&quot;videoThumb&quot; id=&quot;'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$video</span><span style="color: #339933;">-/&gt;</span>getFlashPlayerUrl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; src=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$miniature</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;&quot; /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// fonction permettant de parcourir les vidéos provenant d'un flux</span>
<span style="color: #000000; font-weight: bold;">function</span> get_results<span style="color: #009900;">&#40;</span><span style="color: #000088;">$videos</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	    <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$videos</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		afficheMiniature<span style="color: #009900;">&#40;</span><span style="color: #000088;">$video</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
	    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Enfin, j&#8217;ai ajouté un petit code JQuery pour permettre l&#8217;affichage d&#8217;un seul player flash (s&#8217;il y en a plusieurs sur une page, celle-ci peut galérer un peu) et de changer la vidéo lorsque l&#8217;on clique sur une miniature. Par défaut (au chargement de la page) on affiche la première vidéo.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">/* ##########
		AFFICHAGE DYNAMIQUE DES VIDEOS
	########## */</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// afficher une video au chargement de la page si le div ayant pour id lectureVideo</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> urlVideo <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img.videoThumb:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;object width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">+</span>urlVideo<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;'</span><span style="color: #339933;">+</span>urlVideo<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img.videoThumb&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si on clique sur une miniature on affiche la vidéo dans le bloc ayant pour id &quot;lectureVideo&quot;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#lectureVideo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;object width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;color1=0x2193bd&amp;color2=0x2193bd&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;360&quot; height=&quot;300&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pour voir la structure HTML que j&#8217;ai utilisé, je t&#8217;invite à regarder le code de la démo (CTRL+U sous firefox). C&#8217;est à toi de jouer maintenant ! <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Toute la code officielle est <a href="http://code.google.com/intl/fr-FR/apis/youtube/overview.html">disponible ici</a>.</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/06/05/tutorial-api-youtube-rechercher-et-afficher-des-videos-php-et-jquery/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Tutorial JQuery : effet de suppression Ajax à la WordPress</title>
		<link>http://blog.arnaud-k.fr/2009/06/03/tutorial-jquery-effet-de-suppression-ajax-a-la-wordpress/</link>
		<comments>http://blog.arnaud-k.fr/2009/06/03/tutorial-jquery-effet-de-suppression-ajax-a-la-wordpress/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 11:05:46 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin JQuery]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=608</guid>
		<description><![CDATA[Dans l&#8217;admin de WordPress (qui utilise JQuery), il y des légers effets de couleurs, d&#8217;apparition. Je trouve qu&#8217;ils ont un rendu qui fait assez classe. Je te propose donc un tutorial pour faire plus ou moins le même effet. Pour&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/06/03/tutorial-jquery-effet-de-suppression-ajax-a-la-wordpress/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F03%2Ftutorial-jquery-effet-de-suppression-ajax-a-la-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F06%2F03%2Ftutorial-jquery-effet-de-suppression-ajax-a-la-wordpress%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Dans l&#8217;admin de WordPress (qui utilise JQuery), il y des légers effets de couleurs, d&#8217;apparition. Je trouve qu&#8217;ils ont un rendu qui fait assez classe.</p>
<p>Je te propose donc un tutorial pour faire plus ou moins le même effet. Pour l&#8217;effet de transition de couleur il est nécessaire d&#8217;avoir le plugin JQuery.color (<a href="http://blog.arnaud-k.fr/effetSuppr/jquery.color.js">dispo ici</a>) et le plugin JQuery.delay pour une meilleure fluidité (au moment de l&#8217;appel en Ajax, <a href="http://blog.arnaud-k.fr/effetSuppr/jquery.delay.js">dispo ici</a>)</p>
<p><a class="demo" title="voir la démo" href="http://blog.arnaud-k.fr/effetSuppr/">Voir la démo</a></p>
<p>Comme d&#8217;habitude, on commence par inporter la librairie JQuery et les plugins nécessaires :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.color.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.delay.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>Ensuite on prépare la structure HTML des éléments à supprimer. J&#8217;ai choisi des paragraphes (balises &lt;p&gt;) pour que ce soit le plus simple possible, mais libre à vous de le changer et par conséquent de changer les sélecteurs JQuery.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Premier élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- on place dans l'attribut rel l'id de l'element à supprimer --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Deuxième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Troisième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Quatrième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Cinquième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Sixième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;6&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Septième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Huitième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Neuvième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Dixième élément <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;supprimer&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span>&gt;</span>Supprimer<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></td></tr></table></div>

<p>Enfin, la plus grosse partie : le code JQuery. Les commentaires sont directement dans le code (ils sont également dans le code de la page de démo).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.supprimer'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// quand on clique sur un lien supprimer</span>
		e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// annule l'effet du lien pour pas recharger la page</span>
		<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on recupere l'id de l'element a supprimer (qui est dans l'attribut rel du lien)</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">confirm</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Supprimer cet élément ?'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// on demande une confirmation</span>
			<span style="color: #003366; font-weight: bold;">var</span> parent <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on recupere le paragraphe parent du lien (qui contient l'element a supprimer)</span>
			$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> 
				type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// les variables seront passées en POST (comme d'hab pour les recuperer en php $_POST[id] par exemple)</span>
				url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;suppr.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// on appelle le fichier php suppr.php qui supprimer l'element de la base de donnees (dans mon cas, ce fichier est vide)</span>
				data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;id=&quot;</span><span style="color: #339933;">+</span>id<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;act=suppr&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// variable que l'on passe au fichier php</span>
				beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					parent.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'backgroundColor'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'#FF3F47'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// animation a faire avant l'envoi (on change le fond avec un fondu jusqu'à la couleur #FF3F47)</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
				success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// en cas de succes</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1200</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// on attend 1.2 secondes</span>
							parent.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// et on fait disparaitre l'element en l'enroulant</span>
							<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/06/03/tutorial-jquery-effet-de-suppression-ajax-a-la-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>phpfonctions, premier bilan et choses à faire</title>
		<link>http://blog.arnaud-k.fr/2009/05/21/phpfonctions-premier-bilan-et-choses-a-faire/</link>
		<comments>http://blog.arnaud-k.fr/2009/05/21/phpfonctions-premier-bilan-et-choses-a-faire/#comments</comments>
		<pubDate>Thu, 21 May 2009 10:49:00 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[bilan]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpfonctions]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=559</guid>
		<description><![CDATA[Voilà, ça fait maintenant une semaine que j&#8217;ai mis en ligne phpfonctions (pour rappel phpfonctions est une bibliothèque de fonctions php). Le premier bilan que je peux en tirer est plutôt positif. Tout d&#8217;abord en terme de fonctions ajoutées :&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/05/21/phpfonctions-premier-bilan-et-choses-a-faire/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F21%2Fphpfonctions-premier-bilan-et-choses-a-faire%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F21%2Fphpfonctions-premier-bilan-et-choses-a-faire%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Voilà, ça fait maintenant une semaine que j&#8217;ai mis en ligne <a href="http://phpfonctions.fr">phpfonctions</a> (pour rappel phpfonctions est <strong>une bibliothèque de <a href="http://phpfonctions.fr">fonctions php</a></strong>). Le premier bilan que je peux en tirer est plutôt positif. Tout d&#8217;abord en terme de fonctions ajoutées : on peut en compter aujourd&#8217;hui <strong>une bonne quarantaine</strong>. Mais c&#8217;est surtout leur variété qui me plaît bien.</p>
<p>Ensuite, en terme de visites, <strong>lundi a été une journée record avec plus de 900 visites</strong> ! Ca redescend tout doucement pour arriver à un total d&#8217;environs 300 visiteurs hier. Au total ce sont <strong>2 224 visiteurs au total</strong> qui sont venus lors de la première semaine (avec plus de <strong>10 000 pages vues</strong> <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' />  )</p>
<p><img class="aligncenter size-full wp-image-561" title="php fonctions, premier bilan" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/05/ilovephp.jpg" alt="php fonctions, premier bilan" width="504" height="200" /></p>
<p>Ce qui a fait la différence, c&#8217;est surtout<strong> les articles sur divers blogs et portails</strong>, avec tout d&#8217;abord Adrien (fidèle lecteur <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) et son blog <a href="http://www.tilacica.com/phpfonctions-bibliotheque-de-fonctions-php,315.html">Tilàcica</a> qui a été le premier sur le coup, puis des articles sur <a href="http://mtnconcept.com/free-tools/code/phpfontions-bibliotheque-de-fonctions-php-en-ligne-961">FreeTools</a>, <a href="http://www.jarodxxx.com/index.php?post/2009/05/16/PhpFonctions%2C-la-bibliotheque-de-fonctions-php">Jarodxxx</a>, <a href="http://www.nexen.net/actualites/php/19069-phpfonctions.php">Nexen</a>, <a href="http://rkueny.fr/developpement-web/phpfonctions">rkueny</a>, <a href="http://www.dominique-girolt.fr/developpement-web/phpfonctions-une-bibliotheque-de-fonctions-php/">dominique-girolt</a>, <a href="http://www.lephpfacile.com/news/4380-phpfonctions">phpfacile</a>, et enfin <a href="http://www.neosting-press.fr/archives/1913">neosting-press</a>. Je les remercie bien entendu tous !</p>
<p>Niveau référencement, Google a l&#8217;air d&#8217;apprécier phpfonctions, en effet sur la <strong>requête fonctions php, il sort sur la première page</strong> en 7-8ème position. Pour ça, il me reste plus qu&#8217;à attendre un peu pour éventuellement recadrer les mots-clés.</p>
<p>Enfin, diverses fonctionnalités ont déjà été ajoutées comme<strong> la <a href="http://phpfonctions.fr/categorie-de-fonctions-php.php?categorie=formulaires">navigation par catégorie</a> ou la possibilité de <a href="http://phpfonctions.fr/rechercher-fonctions-php.php">rechercher une fonction php</a></strong>. J&#8217;ai également eu (en plus des articles cités ci-dessus) quelques propositions ou suggestions intéressantes de la part de <a href="http://twitter.com/Neiths">@neiths</a> (avec son <a href="http://www.emilie-navarro.fr/blog/">blog sympa</a>), <a href="http://twitter.com/dryzer">@dryzer</a>, Cydelic et Mazzu (directement sur <a href="http://blog.arnaud-k.fr/2009/developpement-web/mise-en-ligne-de-phpfonctions/#comment-214">le blog</a>). Je pense que tout bientôt seront disponibles <strong>les flux RSS des commentaires</strong>, un petit encart fonctions php similaires, et <strong>pourquoi pas une API</strong> permettant à divers sites de reprendre le contenu. Pour certaines propositions (comme l&#8217;insertion des classes ou de tutoriels) il faut encore que je réfléchisse, car je voulais garder ce site le plus simple possible sans que ça devienne un portail ou une usine à gaz.</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/05/21/phpfonctions-premier-bilan-et-choses-a-faire/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>API géolocalisation adresse IP avec iplocationtools</title>
		<link>http://blog.arnaud-k.fr/2009/05/14/api-geolocalisation-dadresse-ip-avec-iplocationtools/</link>
		<comments>http://blog.arnaud-k.fr/2009/05/14/api-geolocalisation-dadresse-ip-avec-iplocationtools/#comments</comments>
		<pubDate>Thu, 14 May 2009 11:53:19 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[geolocalisation]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=524</guid>
		<description><![CDATA[J&#8217;avais un peu étudié les différentes solutions d&#8217;API de géolocalisation d&#8217;adresse IP il y a quelques temps. J&#8217;étais sur cette solution tout simple : iplocationtools. Iplocationtools est une API que l&#8217;on peut appeler directement en PHP (voir le code ci-dessous).&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/05/14/api-geolocalisation-dadresse-ip-avec-iplocationtools/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F14%2Fapi-geolocalisation-dadresse-ip-avec-iplocationtools%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F14%2Fapi-geolocalisation-dadresse-ip-avec-iplocationtools%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><img class="aligncenter size-full wp-image-525" title="geolocalisation d'adresse ip" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/05/geoloc.png" alt="geolocalisation d'adresse ip" width="600" height="200" /></p>
<p>J&#8217;avais un peu étudié les différentes solutions d&#8217;<strong>API de géolocalisation d&#8217;adresse IP</strong> il y a quelques temps. J&#8217;étais sur cette solution tout simple : <a href="http://iplocationtools.com/">iplocationtools</a>.</p>
<p>Iplocationtools est une API que l&#8217;on peut appeler directement en PHP (voir le code ci-dessous). Cela crée un fichier XML contenant toutes les infos nécessaires à la géolocalisation (<strong>pays, region, ville, latitude et longitude </strong>principalement). Il ne reste plus qu&#8217;à le parser.</p>
<p>Code à intégrer pour appeler l&#8217;API :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> locateIp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$d</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.iplocationtools.com/ip_query.php?ip=<span style="color: #006699; font-weight: bold;">$ip</span>&amp;output=xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on charge l'api</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Failed to open connection</span>
&nbsp;
    <span style="color: #000088;">$answer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXMLElement<span style="color: #009900;">&#40;</span><span style="color: #000088;">$d</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Status</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'OK'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Invalid status code</span>
&nbsp;
        <span style="color: #000088;">$country_code</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CountryCode</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$country_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">CountryName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$region_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">RegionName</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$city</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">City</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$zippostalcode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ZipPostalCode</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$latitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Latitude</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$longitude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$answer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Longitude</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Return the data as an array</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'latitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$latitude</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'longitude'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$longitude</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'zippostalcode'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$zippostalcode</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'city'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$city</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'region_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$region_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'country_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$country_name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'country_code'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$country_code</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ip'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>A toi de jouer maintenant !</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/05/14/api-geolocalisation-dadresse-ip-avec-iplocationtools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Solution d&#8217;import de contact en PHP (GMail, Hotmail, Twitter&#8230;) : OpenInviter</title>
		<link>http://blog.arnaud-k.fr/2009/05/06/solution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter/</link>
		<comments>http://blog.arnaud-k.fr/2009/05/06/solution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:37:08 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[GMail]]></category>
		<category><![CDATA[openinviter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=476</guid>
		<description><![CDATA[J&#8217;ai découvert il y a peu, cette solution d&#8217;import de contact via des webmail ou des réseau sociaux. OpenInviter permet donc de proposer un système d&#8217;invitation sur n&#8217;importe quel site. Beaucoup de webmails et de réseau sociaux sont disponibles :&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/05/06/solution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F06%2Fsolution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F05%2F06%2Fsolution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>J&#8217;ai découvert il y a peu, cette solution d&#8217;import de contact via des webmail ou des réseau sociaux. <a href="http://openinviter.com">OpenInviter</a> permet donc de proposer un système d&#8217;invitation sur n&#8217;importe quel site. Beaucoup de webmails et de réseau sociaux sont disponibles : GMail, Hotmail, Yahoo Mail, Twitter, MySpace, Skyblog &#8230; (en ce moment, ça ne fonctionne pas avec Facebook).</p>
<p>Pour mettre en place cet outil, il faut s&#8217;inscrire sur le site d&#8217;<a href="http://openinviter.com">OpenInviter</a> et téléchager tous les fichiers nécessaires. Un exemple est même fourni avec, il ne reste plus qu&#8217;à l&#8217;adapter à ton site ! Des connaissances en PHP sont quand même nécessaires pour comprendre la logique de l&#8217;outil.</p>
<p>Je suis en train de le mettre en place sur un premier site (<a href="http://www.coconews.com">Coconews</a>) et d&#8217;autres installations devrait suivre !</p>
<p><a href="http://openinviter.com"><img class="aligncenter size-full wp-image-478" title="openinviter, importer vos contacts via GMail, Hotmail, Twitter..." src="http://blog.arnaud-k.fr/wp-content/uploads/2009/05/openinviter.jpg" alt="openinviter, importer vos contacts via GMail, Hotmail, Twitter..." width="600" height="300" /></a></p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/05/06/solution-dimport-de-contact-en-php-gmail-hotmail-twitter-openinviter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tutorial : suggestions (auto-complétion) en Ajax avec JQuery et Php</title>
		<link>http://blog.arnaud-k.fr/2009/04/28/tutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php/</link>
		<comments>http://blog.arnaud-k.fr/2009/04/28/tutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 11:47:22 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[auto-complétion]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[suggestion]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=390</guid>
		<description><![CDATA[Pour ce deuxième tutoriel sur l&#8217;ajax, je te propose un formulaire avec auto-complétion. Simplement afficher des suggestions quand l&#8217;utilisateur commence à taper dans un champ de texte. Les suggestions sont affichées grâce à Ajax qui permet d&#8217;effectuer des requêtes SQL&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/04/28/tutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F04%2F28%2Ftutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F04%2F28%2Ftutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Pour ce deuxième tutoriel sur l&#8217;ajax, je te propose <strong>un formulaire avec auto-complétion</strong>. Simplement afficher des suggestions quand l&#8217;utilisateur commence à taper dans un champ de texte. Les suggestions sont affichées grâce à Ajax qui permet d&#8217;effectuer des requêtes SQL en &laquo;&nbsp;arrière-plan&nbsp;&raquo; de la page. Toute la partie JavaScript sera faite grâce au framework JQuery.</p>
<p><img class="aligncenter size-full wp-image-391" title="auto-completion avec Ajax et Jquery" src="http://blog.arnaud-k.fr/wp-content/uploads/2009/04/auto-completion.png" alt="auto-completion avec Ajax et Jquery" width="600" height="200" /></p>
<p>Comme d&#8217;hab, j&#8217;ai préparé <strong>une page de démo du script : <a href="http://blog.arnaud-k.fr/autoComplete/">disponible ici</a></strong>. Et il est également possible de <a href="http://blog.arnaud-k.fr/autoComplete/autoComplete.zip">télécharger les fichiers sources de cette démo</a>. Et bien sûr, tout le code présenté ici est dépouillé de toute mise en forme (libre à toi de le personnaliser après !).</p>
<p><a class="demo" title="démo JQuery : auto-complétion" href="http://blog.arnaud-k.fr/autoComplete/">Jquery : auto-complétion</a></p>
<p>Donc, pour commencer, on va préparer le code HTML nécessaire : le champ de texte sur lequel les suggestions vont être appliqué et le bloc (caché au début de la page) qui va éventuellement contenir les suggestions :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		Rechercher un pays :
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputString&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!--  champ texte à analyser pour les suggestions --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;suggestionsBox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;suggestions&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;display: none;&quot;</span>&gt;</span> <span style="color: #808080; font-style: italic;">&lt;!-- bloc contenant les eventuelles suggestions --&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;upArrow.png&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;position: relative; top: -12px; left: 30px;&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;upArrow&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> <span style="color: #808080; font-style: italic;">&lt;!-- image de la fleche vers le haut --&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;suggestionList&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;autoSuggestionsList&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- liste contenant les suggestions --&gt;</span>
			<span style="color: #ddbb00;">&amp;nbsp;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Ensuite, dans <strong>le code javascript</strong>, on retrouve <strong>les deux fonctions nécessaires</strong> : lookup qui permet de faire l&#8217;appel ajax et fill qui permet, comme son nom l&#8217;indique, de remplir le champ avec la valeur suggerée. Après avoir défini les deux fonctions, on ajoute les &laquo;&nbsp;écouteurs&nbsp;&raquo; (qui permettent de surveiller si un événement est effectué) avec keyup (quand on appuie sur le clavier, à la remontée de la touche) et blur (quand le champ texte perd le focus).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> lookup<span style="color: #009900;">&#40;</span>inputString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>inputString.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si le champs txte est vide</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#suggestions'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// on cache les suggestions</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// sinon</span>
			$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>queryString<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">+</span>inputString<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// on envoit la valeur du champ texte dans la variable post queryString au fichier ajax.php</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#suggestions'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// si il y a un retour, on affiche la liste</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#autoSuggestionsList'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// et on remplit la liste des données</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> fill<span style="color: #009900;">&#40;</span>thisValue<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// remplir le champ texte si une suggestion est cliquée</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#inputString'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>thisValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;$('#suggestions').hide();&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// lorsque la page est entierement chargée</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#inputString&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si on presse une touche du clavier en étant dans le champ texte qui a pour id inputString</span>
		lookup<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#inputString&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">blur</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si le champs texte perd le focus</span>
		fill<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Enfin, il ne reste plus qu&#8217;à développer le php qui sera exécuté grâce à l&#8217;appel ajax. Dans ce script, on  récupère la valeur passée (ce qui est saisi dans le champ texte) et il n&#8217;y a plus qu&#8217;à <strong>faire une requête SQL dans la base de données</strong> et d&#8217;afficher les résultats sous forme de liste (avec en prime un petit onClick=fill() sur chaque élément de liste permettant de remplir le champ texte.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">﻿<span style="color: #339933;">&lt;</span> ?php	
&nbsp;
	<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hote de la base&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;login&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;pass&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Impossible de se connecter : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;db278690514&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// si une variable queryString a été posté</span>
               <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'queryString'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// si la longueur du contenu de la variable est superieur à 0			</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// requete sql à personnaliser pour correspondre à votre base de données</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT value FROM countries WHERE value LIKE '<span style="color: #006699; font-weight: bold;">$queryString</span>%' LIMIT 10&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #666666; font-style: italic;">// on parcourt les resultats</span>
					<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pays</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">// on affiche les resultats dans un element de liste en ajoutant </span>
                                                <span style="color: #666666; font-style: italic;">// la fonction fill sur l'evenenement onClick</span>
		         			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li onClick=&quot;fill(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$pays</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\');&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$pays</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
	         		        <span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Il y a une probleme avec la requete sql.'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span> 
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Il ne devrait pas avoir un accès direct à ce script !!!'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Tutoriel basé sur celui du blog nodstrum : <a href="http://nodstrum.com/2007/09/19/autocompleter/">http://nodstrum.com/2007/09/19/autocompleter/</a></p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/04/28/tutorial-suggestions-auto-completion-en-ajax-avec-jquery-et-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Tutorial : connexion en AJAX avec JQuery et PHP</title>
		<link>http://blog.arnaud-k.fr/2009/04/22/tutorial-connexion-en-ajax-avec-jquery-et-php/</link>
		<comments>http://blog.arnaud-k.fr/2009/04/22/tutorial-connexion-en-ajax-avec-jquery-et-php/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 12:12:54 +0000</pubDate>
		<dc:creator>arnaud</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formulaire de connexion]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.arnaud-k.fr/?p=310</guid>
		<description><![CDATA[Pour ce premier tutorial AJAX, je propose un simple formulaire de connexion sans rafraichissement de la page. Ca permettra également d&#8217;introduire un peu de php sur le blog. Il est possible d&#8217;essayer une démo (login : test, mot de passe&#160;[...]</p> <p class="read-more"><a class="gray normal" href="http://blog.arnaud-k.fr/2009/04/22/tutorial-connexion-en-ajax-avec-jquery-et-php/">Lire la suite&#160;&#62;&#62;</a></p>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F04%2F22%2Ftutorial-connexion-en-ajax-avec-jquery-et-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.arnaud-k.fr%2F2009%2F04%2F22%2Ftutorial-connexion-en-ajax-avec-jquery-et-php%2F&amp;source=arnaudk&amp;style=compact&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>
Pour ce premier tutorial AJAX, je propose un simple f<strong>ormulaire de connexion sans rafraichissement de la page</strong>. Ca permettra également d&#8217;introduire un peu de php sur le blog.
</p>
<p><img src="http://blog.arnaud-k.fr/wp-content/uploads/2009/04/connexion-ajax.png" alt="connexion en ajax avec JQuery et PHP" title="connexion en ajax avec JQuery et PHP" width="600" height="200" class="alignnone size-full wp-image-311" /></p>
<p>
<strong>Il est possible d&#8217;<a href="http://blog.arnaud-k.fr/connexionAjax/">essayer une démo</a> (login : test, mot de passe : ajax) ou de <a href="http://blog.arnaud-k.fr/connexionAjax/connexionAjax.zip">télécharger la source</a> de cette démo</strong> (fichier php et mise en forme css inclus). Tout le code affiché ici sera du code dépouillé de tout mise en forme.
</p>
<p>
Pour commencer, on va <strong>préparer le formulaire HTML</strong> servant à la connexion. Deux champs sont nécessaires : nom d&#8217;utilsateur et mot de passe. Il ne faut pas oublier de donner un id (ici &laquo;&nbsp;connexionForm&nbsp;&raquo;) au formulaire pour la gestion des évènements avec JQuery. J&#8217;ai également ajouté un <strong>span vide qui contiendra éventuellement un message d&#8217;erreur</strong> si le login ou le mot de passe n&#8217;est pas bon.
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;connexionForm&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;connexionForm&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- début du formulaire de connexion --&gt;</span>   
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;erreur&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- span qui contiendra les éventuels messages d'erreur --&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login&quot;</span>&gt;</span>Nom d'utilisateur :<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;login&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- champ pour le login --&gt;</span>
&nbsp;
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pass&quot;</span>&gt;</span>Mot de passe :<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;password&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pass&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pass&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- champ pour le mot de passe --&gt;</span>
&nbsp;
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Je me connecte&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bouton&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- bouton de connexion --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span><span style="color: #808080; font-style: italic;">&lt;!-- fin du formulaire --&gt;</span></pre></td></tr></table></div>

<p>
On passe ensuite à la partie JQuery. On commence par charger le framework dans le fichier html (entre les balises &lt;head&gt; et &lt;/head&gt;).
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>
A nous de jouer maintenant. <strong>L&#8217;appel en Ajax ne se fera qu&#8217;à la soumission du formulaire</strong> (avec l&#8217;événement &laquo;&nbsp;submit()&nbsp;&raquo;, ligne 2).
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#connexionForm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">// à la soumission du formulaire						 </span>
		$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// fonction permettant de faire de l'ajax</span>
		   type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// methode de transmission des données au fichier php</span>
		   url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;login.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// url du fichier php</span>
		   data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;login=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#login&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&amp;pass=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#pass&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// données à transmettre</span>
		   success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// si l'appel a bien fonctionné</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>msg<span style="color: #339933;">==</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// si la connexion en php a fonctionnée</span>
				<span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div#connexion&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;span id=<span style="color: #000099; font-weight: bold;">\&quot;</span>confirmMsg<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;Vous &amp;ecirc;tes maintenant connect&amp;eacute;.&lt;/span&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #006600; font-style: italic;">// on désactive l'affichage du formulaire et on affiche un message de bienvenue à la place</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #006600; font-style: italic;">// si la connexion en php n'a pas fonctionnée</span>
				<span style="color: #009900;">&#123;</span>
					$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#erreur&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>bomb.png<span style="color: #000099; font-weight: bold;">\&quot;</span> style=<span style="color: #000099; font-weight: bold;">\&quot;</span>float:left;<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&amp;nbsp;Erreur lors de la connexion, veuillez v&amp;eacute;rifier votre login et votre mot de passe.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #006600; font-style: italic;">// on affiche un message d'erreur dans le span prévu à cet effet</span>
				<span style="color: #009900;">&#125;</span>
		   <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// permet de rester sur la même page à la soumission du formulaire</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
Enfin, il ne reste plus qu&#8217;à <strong>créer le fichier php (login.php)</strong> permettant de tester les paramètres de connexion en testant dans la base de données des membres, si le login et le mot de passe correspondent (ce code est ultra-simplifié, il n&#8217;est pas forcément très sécurisé <img src='http://blog.arnaud-k.fr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ). <strong>Si la connexion est validée, on créé un cookie</strong> (que l&#8217;on pourra tester par la suite avec la fonction &laquo;&nbsp;isset($_COOKIE[id])&nbsp;&raquo; ).<br />
Contenu du fichier login.php :
</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// connexion avec la base de données</span>
<span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Impossible de se connecter : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nomDeMaBase&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// on exécute maintenant la requete sql pour tester si les parametres de connexion sont ok</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT login, pass, id FROM membres WHERE login = '<span style="color: #006699; font-weight: bold;">$_POST[login]</span>' AND pass = '<span style="color: #006699; font-weight: bold;">$_POST[pass]</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$membre</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>login<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #000088;">$membre</span><span style="color: #009900;">&#91;</span>login<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>pass<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #000088;">$membre</span><span style="color: #009900;">&#91;</span>pass<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$membre</span><span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// genere un cookie contenant l'id du membre</span>
	<span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;login&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$membre</span><span style="color: #009900;">&#91;</span>login<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// genere un cookie contenant le login du membre		</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on 'retourne' la valeur 1 au javascript si la connexion est bonne</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> 
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// on 'retourne' la valeur 0 au javascript si la connexion n'est pas bonne</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
C&#8217;est tout pour le premier tutorial AJAX/JQuery/PHP. Cela permet <strong>un premier contact avec AJAX</strong> qui peut être facilement mis en place grâce à JQuery (on économise beaucoup de lignes de codes par rapport au &laquo;&nbsp;JavaScript normal&nbsp;&raquo;&#8230;).</p>


<p>Pas encore de billet sur le même sujet !</p>]]></content:encoded>
			<wfw:commentRss>http://blog.arnaud-k.fr/2009/04/22/tutorial-connexion-en-ajax-avec-jquery-et-php/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
	</channel>
</rss>

