thanks a lot it works like a charm ;)
I finally understood how all this was working !!!!



Matt Grimm-2 wrote:
> 
> This is really a PHP question...
> 
> Your foreach loop is redefining the $returnData variable with every
> iteration, so you'll only end up returning the last country in the
> array. It looks like your mysql_fetch_array loop is also flawed in that
> it writes to the same variables with each loop, effectively saving only
> the last one. I think you might be looking for something more like this:
> 
> ---
> 
> $rows = array();
> while ( $row = mysql_fetch_array($result) ) 
> {
>       $rows[] = $row;
> }
> 
> $returnXML = "<?xml version=\"1.0\"?>";
> $returnXML.= "<ajaxresponse>";
> 
> foreach ($rows as $row) 
> {
>       $returnXML .=  "  <item>";
>       $returnXML .=  "
> <text><![CDATA[<strong>{$row['iso2']}</strong><br>$name]]></text>";
>       $returnXML .=  "    <value><![CDATA[{$row['iso2']}]]></value>";
>       $returnXML .=  "
> <district><![CDATA[{$row['continent']}]]></district>";
>       $returnXML .=  "
> <population><![CDATA[{$row['population']}]]></population>";
>       $returnXML .=  "  </item>";
> }
> 
> $returnXML.= "</ajaxresponse>";
> 
> echo $returnXML;
> 
> ---
> 
> Let me know if I missed something or if this works out for you.
> 
> m.
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of eugene33
> Sent: Thursday, December 14, 2006 7:41 AM
> To: [email protected]
> Subject: Re: [jQuery] jquery autocomplete and mysql
> 
> 
> Thanks Matt
> 
> I'm trying to build this PHP backend, again my skills are not so good so
> if
> anyone could point me in the right direction ;)
> 
> 
> Here is what I come with, expecting to extract the data from my db and
> then
> sort them under a xml skeleton 
> So now it's working but I have only one country (the first one). The
> foreach
> function must be the problem, but I really can't figure why
> 
> <?php
>     header('Content-type: text/xml');  // output as XML
> // $q = strtolower($_GET["q"]);
> // if (!$q) return;
>         // connect to MySQL & load database
>         mysql_connect('localhost','xxx','xxx');
>         if ([EMAIL PROTECTED]('xxx')) { exit('<p>Unable to locate the '
> .
> $database . ' database at this time.</p>'); }
>        
>         // retrieve customer data
>         $query="SELECT iso_alpha2, name, population, continent FROM
> countryinfo ORDER BY iso_alpha2 DESC";
>         $result=mysql_query($query);
>         if (!$result) { exit('<p>Error performing query: ' .
> mysql_error() .
> '</p>'); }
>        
>         // close db
>         mysql_close();
>        
>         while ($row = mysql_fetch_array($result)) {
>               $iso2 = $row['iso_alpha2'];
>               $name = $row['name'];
>               $population = $row['population'];
>               $continent = $row['continent'];
>                 // etc. etc.
>       }
> $rows = array('iso_alpha2');
> foreach ($rows as $row) {
>  $returnData =  "  <item>";
>  $returnData.=  "    <text><![CDATA[<strong>$iso2</strong><br
>>$name]]></text>";
>  $returnData.=  "    <value><![CDATA[$iso2]]></value>";
>  $returnData.=  "    <district><![CDATA[$continent]]></district>";
>  $returnData.=  "    <population><![CDATA[$population]]></population>";
>  $returnData.=  " </item>";
> }
>  $returnXML = "<?xml version=\"1.0\"?>";
>  $returnXML.=  "<ajaxresponse>";
>  $returnXML.=  "$returnData";
>  $returnXML.=  "</ajaxresponse>";
> 
> echo $returnXML;
> ?>
> -- 
> View this message in context:
> http://www.nabble.com/jquery-autocomplete-and-mysql-tf2783514.html#a7876
> 110
> Sent from the JQuery mailing list archive at Nabble.com.
> 
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/jquery-autocomplete-and-mysql--SOLVED--tf2783514.html#a7988420
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to