If in my category there are 6 article and the category is set to show only 4 article, than the pagination is show. Well when i clic on second page, the random function randomize all the article, so in the second page i can view article just showed in the first page and some article that are supposed to be in second page are muved on firts.
On the screenshot 1 there is the first page, the article order is:
On the screenshot 2, after clik on secon page, the article is:
I expect that the randomization is based on the pagination, so only article that are not showed in the previous page are randomized
The randomization do not care about which article is just showed, so one article is showed 2 times (the C) and one in not showed at all (the F, the article are 6).
database 5.6.35-1dotdeb+7.1dotdeb+7.1
PHP 5.6.30-1
Joomla! 3.7.0 Stable [ Amani ] 25-April-2017 15:36 GMT
Joomla Platform 13.1.0 Stable [ Curiosity ] 24-Apr-2013 00:00 GMT
Template: Beez3 and Protostar
I read this thread:
<http://stackoverflow.com/questions/10729633/php-mysql-pagination-with-random-ordering
as i can understand this depend on the type of SQL query, and the result is a "bug" in the the article pagination.
Please tell me if i need to explain in better way.
Thak you for support our community
S.
Status | New | ⇒ | Confirmed |
set Status "Confirmed" in Issue Tracker.
Problem is that we need $query->RAND() to order same in subsequent calls of the pagination ...
If accepting that it is proper to have random order per user session
We can do this, at places that use:
$query->Rand();
we could use:
// Get shared seed from session,
$session = JFactory::getSession();
$seed = $session->get('common_query_rand_seed', null);
// Creating seed if it does not exist and store seed into session
if ($seed===null)
{
$seed = rand(); // 0 to getrandmax()
$seed = $session->set('common_query_rand_seed', $seed);
}
// Now call a new API method, this is needed since
// some DBs use seperate method for initializing randomizer
$query->setRandSeed($seed);
$query->Rand();
$query->setRandSeed(null); // Clear it !!
Now DB drivers changes
e.g. for MySQL it would be
public function setRandSeed($seed=null)
{
$this->seed = $seed;
}
public function Rand($seed=null)
{
return $this->seed===null
? ' RAND() '
: ' RAND('.(int)$seed.')';
}
e.g. for Postgresql no changes to Rand only the newly added setRandSeed($seed=null)
public function setRandSeed($seed=null)
{
// Use given seed
if ($seed!==null)
{
$this->seed = ((int) $seed) / getrandmax();
}
// Effectively we want to re-seed here with a new random number
else
{
$this->seed = rand() / getrandmax();
}
pg_query($this->connection, 'SELECT setseed(' . $this->seed . ')');
}
hi ggppdk,
i'm not sure if i have understood.
The new random function is call the first time the user visit one of the pages of the category (set in random order).
Is it correct even if the page was, for example, the second?
After the user call the new random order, every visit of other pages by click on pagination bar are in the same order?
When user call another page the session in set to null?
Is it correct?
thank you
S.
@stefano-buscaglia ,
my answer was meant for DB developers, to get comments
In short,
in order for query giving the articles to produce same "random" order,
thus pagination will work correctly
It needs to be "seeded" with the same number
e.g. if you use 3 times (3 pages) this
$seed_from_session = 451123; // some seed stored in session
return ' RAND('.$seed_from_session.')';
return ' RAND('.$seed_from_session.')';
return ' RAND('.$seed_from_session.')';
without a seed if you use 3 times (3 pages) this
return ' RAND()';
return ' RAND()';
return ' RAND()';
Status | Confirmed | ⇒ | Information Required |
@ggppdk can you make a Pull Request?
That would mean testing with all supported DBs,
unfortunately, i can not do this now
I have suggested the needed code above for all DBs,
someone with skills for all DBs could do such a PR
Status | Information Required | ⇒ | Needs Review |
I also note that the same behavior is present in the pagination of the article for TAG in random order.
If I create a module "Popular - Tag" and I set random order, at any click on the single TAG the order of the TAGs change and this makes it virtually impossible to understand which TAG was just clicked (the user need to remember the name of the TAG instead of the position of the TAG's label.
S.
@stefano-buscaglia if this is a different Issue please open a new one if there isn't a Issue opened already.
I think the origin of this issue is the same that cause the problem for the pagination in random order, that, as I can say, is the type of SQL query mentioned here[1] and confirmed by @ggppdk
[1] <http://stackoverflow.com/questions/10729633/php-mysql-pagination-with-random-ordering
Labels |
Added:
J3 Issue
|
Thank you for raising this issue.
Joomla 3 is now in security only mode with no further bug fixes or new features.
This is still an issue in Joomla 4 and reading the comments above and on the linked SO discussion I am not sure it can ever be truly resolved and it should be a known issue that any random order will not work as expected when there is pagination.
I am going to leave it open however and ask that the tag is updated for Joomla 4. Who know, maybe it will scratch someones itch and they will work on a usable solution.
Labels |
Added:
No Code Attached Yet
J4 Issue
Removed: J3 Issue ? |
I have changed the label but I don't think this will be fixed at any time. You need to store the data of the shown artikels in the session and then add the already shown artikels as a not in (id1, id2, id3 ...) this will make the site slower. I personally think the random and pagination together makes no sense at all.
Status | Needs Review | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-02-18 17:46:01 |
Closed_By | ⇒ | Hackwar |
We have now 2023 and this is still open. The way I see it, the randomized order means that on each page load all articles are shuffled again. Yes, that means that pagination doesn't really work, but that is more or less expected behavior. A "static" randomization is not something we offer right now. So this is a WONTFIX and I'm closing the issue. Thank you all for your time and contributions in this discussioon.
I can confirm the problem in Joomla 3.7.1
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16081.