找到你要的答案

Q:php limit offset distribution for multiple subqueries

Q:多个查询PHP极限偏分布

I have the following piece of code to get a list of notification items:

public function actionMynotifications($offset,$auth_key)
{
 $limit = intval(1);
 while ($limit >= intval(5)) {
     //
 }
 $this->findA($offset,$limit,$userid);
 $this->findB($offset,$limit,$userid);
 $this->findC($offset,$limit,$userid);
 $this->findD($offset,$limit,$userid);
 $this->findE($offset,$limit,$userid);

As input the Url queries on it with increasing the $offset. And as a limit I want to have 5. But this is a list of different types that shall be sorted by the created_at that I enter so when it is one result that is returned as array:

$this->findA($offset,$limit,$userid)['created_at'];

My idea is to compare all the routes to find the "newest" created_at and repeat this until I have a list of 5 (limit) on $offset 0.

My problem is that I do not get an idea where to start for a performant comparison loop that does not result in many if else statements. $offset and $limit have to be consistent for results like because it is not clear where the youngest items are.

(offset=0/limit=5) A A A B E

or (offset=5/limit=5) A A A B E

A C D A B

Gladly I give more information when needed just comment it.

Or is it more intelligent to set an extra table for each user with abstractions that contains just the created_at,type(for table),id and is re-sorted completely in intervals to provide this?

Or maybe make this last in the cache. And query this.

我有以下代码来获取通知项列表:

public function actionMynotifications($offset,$auth_key)
{
 $limit = intval(1);
 while ($limit >= intval(5)) {
     //
 }
 $this->findA($offset,$limit,$userid);
 $this->findB($offset,$limit,$userid);
 $this->findC($offset,$limit,$userid);
 $this->findD($offset,$limit,$userid);
 $this->findE($offset,$limit,$userid);

作为输入的URL查询,它增加了$偏移。作为一个限制,我想有5。但这是一个列表的不同类型,应按created_at我进入所以当它是一个结果,返回的数组:

$this->findA($offset,$limit,$userid)['created_at'];

我的想法是比较所有的路线,找到“最新”created_at重复直到我有一个5美元(限制)偏移0。

我的问题是我不知道从哪里开始的一个高性能的比较循环,如果没有else语句导致许多。美元和美元的限制必须是一致的结果,因为它不清楚哪里最年轻的项目是。

(offset=0/limit=5) A A A B E

or (offset=5/limit=5) A A A B E

A C D A B

很高兴我提供更多的信息时,需要评论。

或者是更聪明的为每个用户提供抽象,仅仅包含created_at设置一个额外的表式(表),身份证和重新排序完全间隔提供这个吗?

或可能使这最后在高速缓存。并查询此。

php  mysql  algorithm  sorting  activerecord