Php怎么展示一对多的关系

WBOY
Release: 2016-06-13 12:16:38
Original
1320 people have browsed it

Php如何展示一对多的关系?
需要展示的效果类似下图:


其中俱乐部一项可能有多个值.

而对应的表结构如下:
CREATE TABLE users(
  uid int(11) NOT NULL AUTO_INCREMENT,
  uname varchar(32),
  PRIMARY KEY (uid)


CREATE TABLE groups(
  gid int(11) NOT NULL AUTO_INCREMENT,
  gname varchar(32),
  PRIMARY KEY (gid)


CREATE TABLE user_group(
  uid int(11),
  gid int(11)


请问怎么样查询出并并用php展示如如图的效果?

------解决思路----------------------
select u.uname , GROUP_CONCAT(g.gname) from users u, user_group ug, groups g 
where u.uid=ug.uid and ug.gid=g.gid group by u.uid;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template