You are here:  » Problem to order by $count


Problem to order by $count

Submitted by rubenxela on Thu, 2010-04-15 12:00 in

Hello,
I've got problem with ordering results but I can't understand why !

I've a very simple xml file of this type :

<title> For area
<description> I use for making url
<link> Numbers of results in this area

<item>
<title>Région LA TRONQUIERE</title>
<description><![CDATA[Région+LA+TRONQUIERE]]></description>
<link><![CDATA[13]]></link>
</item>
<item>
<title>Divers DORDOGNE</title>
<description><![CDATA[Divers+DORDOGNE]]></description>
<link><![CDATA[5]]></link>
</item>

/!\ Here come approximativly 10 - 15 other results and continue with/!\

<item>
<title>Divers GERS</title>
<description><![CDATA[Divers+GERS]]></description>
<link><![CDATA[1]]></link>
</item>
<item>

// /!\ This is the same feed but I cut it to show where is the problem. Script Can't display after this item

<title>Région BRIVE</title>
<description><![CDATA[Région+BRIVE]]></description>
<link><![CDATA[11]]></link>
</item>
<item>
<title>Région BAGNAC</title>
<description><![CDATA[Région+BAGNAC]]></description>
<link><![CDATA[7]]></link>
</item>
<item>
<title>Divers CORREZE</title>
<description><![CDATA[Divers+CORREZE]]></description>
<link><![CDATA[8]]></link>
</item>
<item>
<title>Divers TARN & GARONNE</title>
<description><![CDATA[Divers+TARN+&+GARONNE]]></description>
<link><![CDATA[1]]></link>
</item>
<item>
<title>Divers AVEYRON</title>
<description><![CDATA[Divers+AVEYRON]]></description>
<link><![CDATA[4]]></link>
</item>
<item>
<title>Région GOURDON</title>
<description><![CDATA[Région+GOURDON]]></description>
<link><![CDATA[12]]></link>
</item>

So with this I use a very simple function to display results ordering by LINK field (numbers of item / area)

So I can do it basicaly like you taught me but :

The script doesn't display items which come after :

<item>
<title>Divers GERS</title>
<description><![CDATA[Divers+GERS]]></description>
<link><![CDATA[1]]></link>
</item>
<item>

I don't know why but I can see that the problem come from the fact that there is "1" (one) in link field for this item.

So with my script I can display results ordering by $count (LINK) BUT does not account the items after "Divers Gers"

Here is my simple parsing script :

<?php
 
require("config.php");
  require(
"MagicParser.php");
 
$records=array();
  function 
myRecordHandlerform($record)
  {
  global 
$records;
    if ((
$record["TITLE"]==FALSE)||($record["TITLE"]=="A déterminer")) return;
$records[] = $record;
  }
  
MagicParser_parse("".$urlsite."navigation.xml","myRecordHandlerform","xml|RSS/CHANNEL/ITEM/");
function 
cmp($a$b)
  {
   if (
$a["LINK"] == $b["LINK"]) {
      return 
0;
    }
    return (
$a["LINK"] > $b["LINK"]) ? -1;
  }
  
usort($records,"cmp");
  
// now display or use the sorted records
  
foreach($records as $record)
  {
       
$region $record["TITLE"];
     
$region2 $region ;
$region2 str_replace(" ","+",$region2);
$region2 str_replace("dé","dé",$region2);
$region2 str_replace("Ré","re",$region2);
  print 
"<option value=\"".$region2."\">".$region." (".$record["LINK"].")</option> \n";
}
?>

Submitted by support on Thu, 2010-04-15 12:13

Hello,

I think this may be the issue affecting some PHP installations that cause problems with extended characters if there are any character encoding issues.

I will email you a version of Magic Parser that cleanses data to UTF-8 before handing it to the parser, which should help...

Cheers,
David.

Submitted by rubenxela on Thu, 2010-04-15 12:24

Thanks I will try it. But I can't understand why it stop everytime after the item where LINK field is 1 (one). I can't imagine that's relative to utf-8 things ! I try and let you know .
Best Regards

Submitted by support on Thu, 2010-04-15 12:29

Hi,

It's worth trying first in case it's co-incidental that the character encoding error is in the next record.

If no joy, if you could reply to the email that I sent you with your script attached I'll check it out for you...

Cheers!
David.

Submitted by support on Thu, 2010-04-15 12:29

Hi,

It's worth trying first in case it's co-incidental that the character encoding error is in the next record.

If no joy, if you could reply to the email that I sent you with your script attached I'll check it out for you...

Cheers!
David.