HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


News archives return results by oldest first

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#52544 (In Topic #11446)
Avatar

Fan in action

Hi,

I'd like my news archives to function as a regular blog i.e. latest results first and then links to older posts via previous and next buttons.

The results seem to be returned by oldest first by default which seems strange to me. I've come up with a fairly spectacularly hacky way of getting them the other way around by messing about with news.php but was wondering if there is some simple way of doing this that I'm missing?

thanks,

a
Back to the top
 
Posted
Rating:
#52576
Avatar

Hi,

I'm quite confused, as I thought it did work like this, just tested it and it does seem to, and the code implies it works too. I am wondering if I am looking at something else (screen shot might help). Or maybe you're on an older version and there's been a bug fix?
Regardless of this, v4.2 is going to have much better blog functionality.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#52579
Avatar

Fan in action

Hi Chris,

Thanks for getting back to me. It's definitely returning them by oldest first on mine.

The bit that was confusing me particularly in news.php was that the ORDER BY option didn't seem to be doing anything for me:

$rows=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'news p'.$join.' WHERE '.$q_filter.((!has_specific_permission(get_member(),'see_unv
alidated'))?' AND validated=1':'').' GROUP BY p.id ORDER BY date_and_time ASC',$max,$start);

Regardless of whether this was ASC or DESC, stuff was coming out in the same order. I'm guessing this is what should arrange the order as the next bit is just going through an associative array so the order doesn't seem to come into it there.

What I've ended up having to do is stick in a custom sort function and do lots of arseing around with stuff like counting the number of records and putting in custom $start points based on that. Also having to rejig the next/previous stuff to work so if there was some simple way around this it would be massively useful for me.

I don't think I'd made any changes to news.php before I noticed the problem…the version I'm on is 4.10…is there anywhere else I should be looking here besides news.php? Can't see anywhere but you never know.

I'm not 100% sure that the code implies it works that way either but in fairness you'd have a better idea seeing as you wrote it  :P

To me it seems as if the previous button is always testing against a max amount for example whereas surely they should be testing against a min?

Anway, totally baffled so I'll just rock out something that works temporarily for what I need on this version and hope it goes for me in 4.2. I'd love to get to the bottom of it though so any assistance appreciated.

cheers,

a

Back to the top
 
Posted
Rating:
#52581
Avatar

Hi,

That's pretty odd. What database software and version are you using?

The original line 301 is actually DESC:

Code

      $rows=$GLOBALS['SITE_DB']->query('SELECT * FROM '.get_table_prefix().'news p'.$join.' WHERE '.$q_filter.((!has_specific_permission(get_member(),'see_unvalidated'))?' AND validated=1':'').' GROUP BY p.id ORDER BY date_and_time DESC',$max,$start);

I'd try and remove "GROUP BY p.id" to see if that might be triggering a MySQL bug.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#52582
Avatar

Fan in action

yup, baffling alright…using MYSQL Server version: 5.0.51a-community

just noticed a warning message in the phpadmin saying "Your PHP MySQL library version 4.1.21 differs from your MySQL server version 5.0.51a. This may cause unpredictable behavior." which is possibly something to do with it but I have "keine Ahnung" what that means as the locals say (no idea…not a sausage).

I had the GROUP BY set to DESC in the original alright, that's how it was when I first noticed the problem so thought changing to ASC might fix it. Neither seem to make any difference.

Tried the p.ID thing yesterday and that made no difference. The problem to me seemed to be that the code will always be returning something starting from an id of 0 (default for $start was 0), which is the first ever entry, rather than from the total number of entries - something.

Mine seem to be starting at 1 and going up n the database. Anyway, total confusion but I think I nearly have it working the way I need it to now with a workaround so I'll just keep my fingers crossed on that.

a
Back to the top
 
Posted
Rating:
#52585
Avatar

To me it seems as if the previous button is always testing against a max amount for example whereas surely they should be testing against a min?

It's checking to see if the number of news items shown is equal to the maximum that may show on the screen. If it is, it deduces that there are probably also more and thus provides a 'Next' link. It's true that there's a 1 in 30 chance of this being incorrect, but I decided this small chance of error was better than running an extra query to check the true row count (would be a small performance hit).

Reading your latest post now…


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#52586
Avatar

just noticed a warning message in the phpadmin saying "Your PHP MySQL library version 4.1.21 differs from your MySQL server version 5.0.51a. This may cause unpredictable behavior." which is possibly something to do with it but I have "keine Ahnung" what that means as the locals say (no idea…not a sausage).

This is not likely related. PHP bundles a copy of the MySQL library and this sometimes is not right for the MySQL version - but I doubt it'd cause this. I don't think the MySQL client library would tear apart the queries then send their constituent parts over to MySQL, which it'd have to do if it were dropping the order clause.

I had the GROUP BY set to DESC in the original alright, that's how it was when I first noticed the problem so thought changing to ASC might fix it. Neither seem to make any difference.

You mean the ORDER BY; the GROUP BY and ORDER BY clauses serve different purposes:
  • The GROUP BY p.id is there to stop multiple copies of the same news item coming up in the results. This can happen if a news item is in multiple categories, and happens due to how JOIN's work.
  • The ORDER BY is simply to do the ordering.


I can't think what could possibly cause this to be honest, and the SQL is pretty standard and straight-forward, so I'm just going to need to put it down to a bug in MySQL or the server configuration somewhere. I don't think it's something we can fix better than you already have, at least not without making a mess of the code.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: