- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下函数以二维数组格式返回所有玩家。下面是函数:-
public function get_football_players($type = FOOTBALL_TEXT, $filter = '', $start = '', $limit = '', $player = '') {
$this->db->select('tblmarkets_football.*, tblmarkets.symbol, tblmarkets.type');
$this->db->from('tblmarkets_football');
$this->db->join('tblmarkets','tblmarkets.id = tblmarkets_football.market_id','left');
if($type != ''){
$this->db->where('type', $type);
}
$this->db->where('active', 1);
switch ($filter) {
case 'forward':
$this->db->where('position', 'Forward');
break;
case 'midfielders':
$this->db->where('position', 'Midfielder');
break;
case 'defenders':
$this->db->where('position', 'Defender');
break;
case 'goalkeepers':
$this->db->where('position', 'Goalkeeper');
break;
case 'highest_price':
case 'lowest_price':
$tmp = $this->external_api_model->get_filtered_football_pairs($limit, $start, $filter);
$players = json_decode($tmp, true);
$this->db->where_in('symbol', $players);
break;
}
if($player != ''){
$this->db->like('tblmarkets_football.name', $player);
}
if($filter != 'highest_price' && $filter != 'lowest_price'){
$this->db->limit($limit, $start);
}
$result = $this->db->get()->result();
return $result;
}
当有人应用最高价格过滤器时,get_filtered_football_pairs API 会以数组格式返回所有球员。我希望所有这些玩家都按照我收到的顺序显示在顶部。 $players
包含所有玩家的名字。目前它们是随机显示的。
任何帮助将不胜感激。提前致谢。
编辑
$players 将如下所示:-
Array
(
[0] => paul-pogba
[1] => neymar
[2] => kylian-mbappé
[3] => lionel-messi
[4] => jadon-sancho
[5] => eden-hazard
[6] => marcus-rashford
[7] => mohamed-salah
[8] => harry-kane
[9] => vinicius-junior
[10] => callum-hudson-odoi
[11] => raheem-sterling
[12] => ousmane-dembele
[13] => anthony-martial
[14] => paulo-dybala
[15] => gareth-bale
[16] => joshua-kimmich
[17] => cristiano-ronaldo
[18] => kai-havertz
[19] => leroy-sané
)
我想要的顺序是首先显示 paul-pogba,然后是 neymar 等等。
最佳答案
这是未经测试的,但逻辑是您转义 $player
数组中的元素,然后将优先处理应用于符合条件的 symbol
值,然后提供次要排序顺序为 symbol
升序(否则在将玩家与非玩家分开后让事情随机。
case 'highest_price':
case 'lowest_price':
$tmp = $this->external_api_model->get_filtered_football_pairs($limit, $start, $filter);
$players = json_decode($tmp, true);
$this->db->where_in('symbol', $players);
foreach ($players as &$p) {
$p = "'" . $this->db->escape_str($p) . "'";
}
$this->db->order_by("IF(FIELD(symbol," . implode(",", $players) . ")=0,1,0),
FIELD(symbol," . implode(",", $players) . ")");
break;
这是一个 db-fiddle 演示,展示了如何执行排序:https://www.db-fiddle.com/f/9yxTo3nEHCu9vLPW6MELy3/1
帮助理解我的技术:https://dba.stackexchange.com/a/109126/157408
解释子句的0,1
部分...
它将$players
分隔在非$players
之前。所有 $players
都将在 0
组中,非 $players
将在 1
中团体。然后二次排序会将 $players
置于您的首选顺序(打破 0
并列)。
附注我认为将 $start
和 $limit
的默认值设置为空字符串是不明智的——数字值似乎更适合。
我通常尽量远离开关 block ,因为我觉得它太冗长了。另一种样式可能如下所示(根据您的预期输入和逻辑要求,您可以进一步简化它):
if (in_array($filter, ['forward', 'midfielders', 'defenders', 'goalkeepers'])) {
$this->db->where('position', ucfirst(rtrim($filter, 's')));
}
if (in_array($filter, ['highest_price', 'lowest_price'])) {
$tmp = $this->external_api_model->get_filtered_football_pairs($limit, $start, $filter);
$players = json_decode($tmp, true);
$this->db->where_in('symbol', $players);
foreach ($players as &$p) {
$p = "'" . $this->db->escape_str($p) . "'";
}
$this->db->order_by("IF(FIELD(symbol," . implode(",", $players) . ")=0,1,0),
FIELD(symbol," . implode(",", $players) . ")");
} else {
$this->db->limit($limit, $start);
}
if ($player != '') {
$this->db->like('tblmarkets_football.name', $player);
}
关于php - 无论 codeigniter 中的排序如何,我都希望在顶部有一组特定的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55120450/
对于我不断地用刽子手问题来打扰这个论坛,我深表歉意。我希望很快就能完成这件事。确实在这方面一直在努力。这是到目前为止我的代码: #include #include #include #defin
这篇文章是 this one 的延续. 我试图了解我是否是唯一一个错过并需要 .NET 泛型类型继承其泛型参数类型之一的能力的人。 面临的挑战是收集支持此功能的令人信服的理由,或者,要知道没有。 我给
我正在使用下面的代码设计一个 3 小时的 JavaScript 倒计时 var count = 10800; var counter = setInterval(timer, 1000); //1
我正在处理验证并放置一个 html 模式属性,并希望在不点击保存/提交按钮的情况下查看错误消息。当我在字段外单击时,它应该根据我的模式条件进行验证。 这是我的代码: Extra Credit Da
我有一个像这样的 mysql 表结构: id int primary key name varchar start_time float 数据可能是这样的: id name
我试图在桌面上保留一张带有描述的图片,然后在移动设备上希望图片在左边,描述在右边……更多的是尽可能让所有内容都在首屏。 我希望桌面上的 DIV 是: 一个一个 BBB 但是在手机上: A B A B
我通过 Stackoverflow 进行了搜索,发现很多人试图避免 CSS 列中的重叠,但实际上我被要求让文本和图像重叠。 更新: 更好的图像解释了我被要求做的事情,以及指向我正在使用的代码的链接。谢
我在我的框架中设置了几个协议(protocol)来处理资源。在其中一个协议(protocol)中,我设置了一个扩展来为 decode 函数提供默认实现。显示代码和发生的情况更简单(请参阅对 fatal
我想同时加载,或者在上面的图像之后立即加载。它会在图像和标题 div 在预加载器内旋转之前不断加载 - 不好!这是 HTML: ✕ Various inv
我目前正在开发一个小游戏。我使用 getKeyCode 来移动我的角色,但问题是我不希望你在按住按钮的情况下能够继续移动。无论如何,我是否可以使用 getKeyCode 仅在第一次单击时注册,然后在释
我需要设置 width 或 max-width 才能让 margin:auto 工作,对吗? Like in this jsFiddle . 问题是,段落宽度等于 max-width,因此文本 blo
您好,我在同一页面上有一个表单和一个 Paypal 订阅按钮。在重定向到 Paypal 付款之前,我想在单击提交表单(通过电子邮件发送给我)时订阅按钮。 > >
我想让用户在点击一个文本字段时感觉就像我们点击一个按钮,在释放按钮后它会在很短的时间内变成橙色,然后闪烁并再次变成它的第一种颜色。当我点击它时它运行良好但没有出现颜色闪烁。 布局文件 主要 Ac
我怎样才能让我的 MediaPlayer 继续播放,即使在手机锁定和屏幕关闭的情况下,我认为它可能必须做一些使其成为服务但不确定的事情。如果是这样,我该如何将其更改为服务,或者是否有更快更简单的修复方
有人可以帮助我理解内存泄漏的概念以及特定数据结构如何促进/防止它(例如链表、数组等)。前段时间我被两个不同的人教过两次——由于教学方法的不同,这让我有点困惑。 最佳答案 维基百科有一个 good de
我希望 HTML 表单在提交后不执行任何操作。 action="" 不好,因为它会导致页面重新加载。 基本上,我希望在按下按钮或有人在输入数据后点击 Enter 时调用 Ajax 函数。是的,我可以删
我正在执行一个程序 say A from another,首先是 fork-ing,然后是 execve()。现在的问题是我希望 A 使用我通常使用 LD_PRELOAD 来完成的库。我如何在 exe
我目前正在为我们公司测试 Autofac。 我们希望有以下规则: 如果接口(interface)只实现了一次,则使用 builder.RegisterAssemblyTypes 自动添加它(见下文)。
正如 Scott Meyers 和 Andrei Alexandrescu 在 this 中概述的那样文章 简单尝试实现双重检查锁定实现在 C++ 中特别是不安全的,并且通常在不使用内存屏障的多处理器
目前我有一些代码可以在点击时改变图像,但这段代码是在一个 php HTML 循环中所以事情变得棘手,点击一个开关会使每个故事的开关都激活,因为它是基于 CSS 运行的.如何让它们独立交换? $("
我是一名优秀的程序员,十分优秀!