English 中文(简体)
PHP: Loop over a groupedguery protocol but re one Value one, one for each “grouping”?
原标题:PHP: Loop over a grouped SQL query array but echo one value once for each “grouping”?

我用手提的一部小篇的法典,试图在几小时左右总结我的脑。

I’m trying to create a query which retrieves some elements and in the end group them by a selector. I’ll try to demonstrate: I’m querying all the members in my organization. Each member is a member of a “department” and there can be several members in each department, but only one department for each member.

因此,我已提出由各部挑选我组织小组所有成员的问题。

当我用简单的<条码”展示时,我只想生产<条码>美元-和>;department_name/code>,但仅供该部使用一次。 现在,它说的是所有5个成员的“市场”,然后对所有这5名成员都修改了“人权”。 我曾尝试过一些不同的方法,例如阵列——unique,从而形成一种功能,即检查扼杀物,看看它是否相同,但却没有结果。

我可以设立两个论坛,但如果我完全不喜欢,因为两个论坛会影响业绩。

任何帮助或建议都会受到高度赞赏。

Sinerely
- Mestika

--- Edited --- By the way, my query looks like this:

SELECT * 
FROM wp_term_taxonomy AS cat_term_taxonomy
INNER JOIN wp_terms AS cat_terms ON cat_term_taxonomy.term_id = cat_terms.term_id
INNER JOIN wp_term_relationships AS cat_term_relationships ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id
INNER JOIN wp_posts AS cat_posts ON cat_term_relationships.object_id = cat_posts.ID
INNER JOIN wp_postmeta AS meta ON cat_posts.ID = meta.post_id
WHERE cat_posts.post_status =   publish 
AND meta.meta_key =   active 
AND meta.meta_value =   active 
AND cat_posts.post_type =   member 
AND cat_term_taxonomy.taxonomy =   deparment 
GROUP BY cat_terms.slug, cat_term_relationships.object_id
最佳回答
$prev_department = NULL;

foreach ($my_query AS $q)
{
  if ($prev_department != $q->department_name)
    echo  <h2> . htmlentities($q->department_name, ENT_COMPAT,  UTF-8 ) . </h2> ;

  // ...

  $prev_department = $q->department_name;
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签