【php处理数据分组问题】教程文章相关的互联网学习教程文章

获取分组的HTML数据到PHP数组? (像复选框的子元素一样)【代码】

如何将此表单结构转换为PHP数组?我也可以编辑HTML,所以每个想法都很好……如果选中了复选框,则此数据将通过保存推送到PHP数组中,所需的结构为:0 =>'group' => 'group_a','type' => 'type_yellow','desc' => 'now to convert' 1 =>'group' => 'group_b','type' => 'type_orange','desc' => 'needed to order'作为示例,我尝试的是通过输入元素名称作为数组,如description [],但我无法控制是否选中了复选框…解决方法:嗯.对于复选框...

php – 按键排序/分组数组【代码】

TL; DR 按键排序/分组数组而不向数组添加另一个级别(由jQuery插件解析的数据)? 细节 我正在构建一个数组以返回一些< select> DOM元素. 它将CC(引擎大小的东西)作为参数并将其用作键,问题在于对数组进行排序. 假设用户选择此范围的CC:50, 100, 125 50 has 32 options available 100 has 3 options available 125 has 12 options available我当前的代码遍历CC,执行SQL以获取选项,并使用循环计数器创建如下的键:$options[$cc. $id]...

php – 按顺序对纬度和经度对进行分组【代码】

我有一张表,每隔x秒写一个位置.该表包含以下列:lat | lon | time | .....最终目标是使地图在设备停止显示图像的点上可见.在随时间存在多个条目的点上,应将行添加在一起以在该位置处显示具有“timeSpent”的行,该行是相同位置处的不同行的差异.所以:lat | lon | timeFirst | timeSpent例如,这是’原始’表:x1,y1, 13:00:12 // Point 1 x1,y2, 13:01:34 // Point 2 x3,y3, 13:02:01 // Point 3 x3,y3, 13:03:03 // Point...

php – 基于公共字符串对数组项进行分组【代码】

我有以下代码,它抓取两个单独的数组,翻转姓氏和名字(也删除逗号)并输出:Director: Bert & Bertie Writer: Bert & Bertie Producer: Louise Knight Producer: Miles Wilkes Producer: Andy Welch Actor: Craig Parkinson Actor: Camilla Rutherford Actor: Paul Bhattarcharjee Actor: Ford Kieman Actor: Maurren the Pug Actor: Hannah Walters DP: Lynda Hall Cut: Matt Chodan我需要做的是将类似的组分组以输出如下内容:Direc...

php – 在foreach中对数组中的项目进行分组和求和【代码】

我循环遍历两个存储过程的结果集,根据另一个存储过程中的字段获取结果. 包含结果集的两个数组是$customers和$subcustomers.foreach($customers as $customer) {foreach($subcustomers as $subcustomer){if($subcustomer['parent'] == $customer['id']){ if($customer['innumber'] == null && $subcustomer['innumber'] != null){ $chartInboundSub['name'] = $customer['name'];$cha...

php – 同一个表,按类型分组最大日期,2行差异【代码】

我怎样才能做到这一点?我有这张桌子╔════════╦══════════╦══════════╗ ║ item ║ price ║ date ║ ╠════════╬══════════╬══════════╣ ║ Dollar ║ 60 ║ 1.3.2016 ║ ║ Dollar ║ 50 ║ 2.3.2016 ║ ║ Bound ║ 100 ║ 1.3.2016 ║ ║ Bound ║ 110 ║ 2.3.2016 ║ ║ Euro ║ 600 ║ 1.3.2016 ║ ║ Euro ║ ...

php – 如何显示分组中的所有列【代码】

我有两个表团队和bobotteam,然后我尝试这个查询:SELECT team.id , bobotteam.teamfight/MAX(bobotteam.teamfight)FROM teamINNER JOIN bobotteam on team.id = bobotteam.id为什么数据只显示1个数据,即使我在bobotteam表中有两个数据.图片解决方法:请试试这个:SELECT team.id , bobotteam.teamfight/(select MAX(bobotteam.teamfight) from bobotteam) FROM team INNER JOIN bobotteam on team.id = bobotteam.id

在php中对数组值进行分组【代码】

我有一个像这样的值的数组:[Organization_id] => Array([0] => 4[1] => 4[2] => 4)但我想要这样的事情:[Organization_id] => Array([0] => 4)提前致谢..解决方法:如果你不关心值关联的关键可能搞乱,你可以使用这个:$array = array_unique($array);

php – Laravel Eloquent – 如何分组条件【代码】

我正在使用以下雄辩的声明Title::where('word', 'lovers')->orWhere('word', 'lover')->where('domain', $resultFromFirstKeyword->domain)->get();我可以通过SQL记录器看到它产生以下SQLselect * from `title` where `word` = 'lovers' or `word` = 'lover' and `domain` = 'www.texasbirdlovers.com'但是我想要生成的SQL是select * from `title` where (`word` = 'lovers' or `word` = 'lover') and `domain` = 'www.texasbirdlo...

按键将平面数组分组为多维数组,如果我们不知道有多少级别. PHP【代码】

我有这个数组:$arr = [ ["id"=>20,"name"=>"a","parent"=>28, ], ["id"=>21,"name"=>"a-child","parent"=>20, ], ["id"=>27,"name"=>"a-child-b","parent"=>20, ], ["id"=>28,"name"=>"A parent","parent"=>0, ], ["id"=>12,"name"=>"no parent","parent"=>0, ]];我想要的是根据父键对其进行分组,其中parent = id&&父母> 0或id是此元素的父元素,如果父键大于零,则元素具有父元素. 在上面的数组中,id = 12没有父节点,id = 20有子节...

php – 按小时按摘要选择和分组行【代码】

我有一个包含视图/点击记录的表.时间存储在unix时间戳中,我需要能够在特定的月/日内(基于时间戳)提取所有时间,但更重要的是,我不知道该怎么做的部分是将它们分组按小时计算.我需要能够在一个查询中执行此操作,而不是循环每小时. 数据库是MySQL,语言是PHP.解决方法: select hour(somedate), count(*) from yourtable group by hour(somedate)如果你需要这三个:select month(somedate), day(somedate), hour(somedate), count(*) fr...

php处理数据分组问题【图】

很简单的一个需求,将数据库取出的二维数组进行按照id分组,同组的数据用逗号连接,例如:处理为就是按照id分组,name进行逗号拼接。 那么按照数据库的思路来说,采用group_concat即可,如果有重复,可使用group_concat(distinct 字段) 即可。(这是有风险的,当数据量足够多的时候会超出group_concat的极限,到时候出现数据截断) 对于PHP而言,可以用很多种方式处理,网友们给出他的解法千奇百怪,但是效率都不是太高,双重循环解...

获取汉字首字母并分组排列 PHP【代码】

1.代码class Character{ /** * 数组根据首首字母排序 */ /** * 二维数组根据首字母分组排序 * @param array $data 二维数组 * @param string $targetKey 首字母的键名 * @return array 根据首字母关联的二维数组 */ public function groupByInitials(array $data, $targetKey = name) { $data = array_map(function ($item) use ($targetKey) { re...

使用mysql或php对带有tags的tag进行分组/格式化【代码】

可以说我们有一个像这样的数组 从像function getGroups($limit = 10) {$data = $this->fetchAll ( 'SELECT gid, `group`, information, tag FROM groups GROUP BY tag LIMIT ' . $limit );return $data; }结果array0 => array'gid' => string '6' (length=1)'group' => string 'Media' (length=5)'tag' => string 'advertising' (length=11)1 => array'gid' => string '8' (length=1)'group' => string 'Fashion' (length=10)'tag'...

php-通过MySQL中的特定关键字对结果进行分组?【代码】

我的网页上有多个带有我正在搜索的关键字的标签,有时它没有使用该关键字进行标签,因此当它具有该标签时,它将在下面返回类似这样的结果, 查询,SELECT* FROM root_pages AS pLEFT JOIN root_mm_pages_tags AS mm ON mm.page_id = p.page_idLEFT JOIN root_tags AS t ON t.tag_id = mm.tag_id AND t.tag_name LIKE '%story%'WHERE p.page_title LIKE '%article title 8%' AND p.page_hide != '1'ORDER BY (t.tag_name+0) ASC结果,pag...

分组 - 相关标签