473,513 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting multiple XML data by date

I am making an RSS parser that takes multiple XML inputs in to an
array and then sorts them by their date value... and it 'almost'
works... I always lose the top value of the second rss feed to be
parsed... its pretty annoying as this is often the most recently
updated RSS item that is missing from my multi-feed...

Help me please:
Currently, I am doing this:

usort($xmlreader_parsed_data, "rss_cmp");

which calls this function:

function rss_cmp($a, $b)
{
$a = strtotime($a->date);
$b = strtotime($b->date);

if ($a == $b) {
return 0;
}
return ($a $b) ? -1 : 1;
}

Aug 15 '07 #1
4 2099
UPDATE: I just added the following to the rss_cmp function, and it
seems to have worked... is it ok? Or will I regret this somewhere?

if (!$a) { return -1; }
if (!$b) { return 1; }

Aug 15 '07 #2
Seems to be a typo, comparison should be $a < $b.

I would make sure error_reporting(E_ALL) is on to see if that gives
any hints.

On Aug 15, 12:08 am, junkmate <junkm...@gmail.comwrote:
I am making an RSS parser that takes multiple XML inputs in to an
array and then sorts them by their date value... and it 'almost'
works... I always lose the top value of the second rss feed to be
parsed... its pretty annoying as this is often the most recently
updated RSS item that is missing from my multi-feed...

Help me please:

Currently, I am doing this:

usort($xmlreader_parsed_data, "rss_cmp");

which calls this function:

function rss_cmp($a, $b)
{
$a = strtotime($a->date);
$b = strtotime($b->date);

if ($a == $b) {
return 0;
}
return ($a $b) ? -1 : 1;
}

Aug 17 '07 #3
putting the coparison that way gives me results the wrong way around.
I want the latest date at the top (ie. the smallest) and to do that I
have to use - shouldnt cause a problem though right?


On Aug 17, 2:10 am, petersprc <peters...@gmail.comwrote:
Seems to be a typo, comparison should be $a < $b.

I would make sure error_reporting(E_ALL) is on to see if that gives
any hints.

On Aug 15, 12:08 am, junkmate <junkm...@gmail.comwrote:
I am making an RSS parser that takes multiple XML inputs in to an
array and then sorts them by their date value... and it 'almost'
works... I always lose the top value of the second rss feed to be
parsed... its pretty annoying as this is often the most recently
updated RSS item that is missing from my multi-feed...
Help me please:
Currently, I am doing this:
usort($xmlreader_parsed_data, "rss_cmp");
which calls this function:
function rss_cmp($a, $b)
{
$a = strtotime($a->date);
$b = strtotime($b->date);
if ($a == $b) {
return 0;
}
return ($a $b) ? -1 : 1;
}

Aug 17 '07 #4
Yes you're definitely right. I thought that might the cause of the
unexpected results. Not sure why data would go missing. I would see if
any warnings are triggered or I guess strtotime could also fail.

On Aug 16, 10:22 pm, junkmate <junkm...@gmail.comwrote:
putting the coparison that way gives me results the wrong way around.
I want the latest date at the top (ie. the smallest) and to do that I
have to use - shouldnt cause a problem though right?

On Aug 17, 2:10 am, petersprc <peters...@gmail.comwrote:
Seems to be a typo, comparison should be $a < $b.
I would make sure error_reporting(E_ALL) is on to see if that gives
any hints.
On Aug 15, 12:08 am, junkmate <junkm...@gmail.comwrote:
I am making an RSS parser that takes multiple XML inputs in to an
array and then sorts them by their date value... and it 'almost'
works... I always lose the top value of the second rss feed to be
parsed... its pretty annoying as this is often the most recently
updated RSS item that is missing from my multi-feed...
Help me please:
Currently, I am doing this:
usort($xmlreader_parsed_data, "rss_cmp");
which calls this function:
function rss_cmp($a, $b)
{
$a = strtotime($a->date);
$b = strtotime($b->date);
if ($a == $b) {
return 0;
}
return ($a $b) ? -1 : 1;
}

Aug 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
4117
by: mike | last post by:
If I had a date in the format "01-Jan-05" it does not sort properly with my sort routine: function compareDate(a,b) { var date_a = new Date(a); var date_b = new Date(b); if (date_a < date_b)...
8
2247
by: nidhog | last post by:
Hello guys, I made a script that extracts strings from a binary file. It works. My next problem is sorting those strings. Output is like: ---- snip ---- 200501221530
18
5719
by: Scott | last post by:
I have a collection where the items in the collection are dates. I want to iterate over the collection and build a value list string for the rowsource of a listbox. The dates in the collection are...
0
3214
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
7
4798
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
3
2088
by: Don | last post by:
I'm using Access 2000. My database collects lots and lots of data. One aspect of that is to collect dimensional data from multiple checks during the day. The way I've done that is to have a...
4
11125
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
3
7304
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
5
4903
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
7257
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.