codeigniter를 사용하고 있으며, 3 개의 다른 테이블을 호출하여 하나의 배열로 결합하려고합니다.MySQL이 3 개의 테이블과 형식을 결합합니다.
$this->db->select('so_alcohol.id,
so_alcohol.name as name,
so_alcohol.category as category,
so_alcohol.permName as permName,
so_alcohol.picture as alcoholPicture,
group_concat(so_user.firstName) as firstName,
group_concat(so_user.lastName) as lastName,
group_concat(so_user.picture) as userPicture,
group_concat(so_rating.idUser) as idUser,
group_concat(so_rating.overall) as overall,
group_concat(so_rating.description) as description');
$this->db->from('alcohol');
$this->db->order_by("id", "desc");
$this->db->join('so_rating', 'so_rating.idAlcohol = so_alcohol.id', 'LEFT');
$this->db->join('so_user', 'so_user.id = so_rating.idUser', 'LEFT');
$query = $this->db->get();
싶습니다 출력은 다음과 같다 : 이것은 내가 무엇을 가지고
Array
(
[0] => stdClass Object
(
[id] => 1
[name] => Product Name
[category] => Product category
[permName] => Product-Name
[alcoholPicture] => http://image.com/1.jpg
[idUser] => 1,2,3
[overall] => 100,80,50
[description] => Review 1,Awesome review 2, Horrible review 3
[firstName] => name 1, name 2, name 3
[lastName] => last 1, last 2, last 3
[userPicture] => http://userimage.com/1.jpg, http://userimage.com/2.jpg, http://userimage.com/3.jpg
)
[0] => stdClass Object
(
[id] => 1
[name] => Product Name
[category] => Product category
[permName] => Product-Name
[alcoholPicture] => http://image.com/1.jpg
[idUser] => 1,2,3
[overall] => 100,80,50
[description] => Review 1,Awesome review 2, Horrible review 3
[firstName] => name 1, name 2, name 3
[lastName] => last 1, last 2, last 3
[userPicture] => http://userimage.com/1.jpg, http://userimage.com/2.jpg, http://userimage.com/3.jpg
)
)
내 질문에 내가 지금이 문제 (즉 I가 나는 일이 무엇을해야합니까 어떻게 찾았습니다.) 먼저 1 개의 결과 만 출력합니다. 40을 출력하고 두 번째를 나타냅니다. so_user.id = so_rating.idUser
왜냐하면 이미 group_concat(so_rating.idUser)
의 아이디어가 있습니까? 난 아직도 PHP 초보자 로서이 일을하는 올바른 방법인지 확실하지 않습니다.
편집 :
알코올
id name category permName picture
1 Product #1 1 Product-1 http://someurl.com/1.jpg
2 Product #2 1 Product-2 http://someurl.com/2.jpg
3 Product #3 1 Product-2 http://someurl.com/3.jpg
4 Product #4 2 Product-2 http://someurl.com/4.jpg
평가
id idUser idProduct overall description
1 1 2 100 Great Product Review 1
2 2 2 75 Great Product Review 2
3 1 3 100 Great Product Review 3
4 2 3 98 Great Product Review 4
사용자
id firstName lastName userPicture
1 first 1 last 1 http://someurlUserPicture.com/1.jpg
2 first 2 last 2 http://someurlUserPicture.com/2.jpg
3 first 3 last 3 http://someurlUserPicture.com/3.jpg
4 first 4 last 4 http://someurlUserPicture.com/4.jpg
나는 도표의 도표를 작성했다. 당신의 요구에 따라 기능별 그룹이 무엇을 할 지 확신하지 못했습니다. php/msql을 사용하여 여전히 녹색입니다. 희망을 통해 내가 배워야 할 것을 배울 수있는 사이트를 만드는 것이 었습니다. 두 번째 부분은 mysql에서'so_user.id = so_rating.idUser'를 수행 할 때 오류가 발생한다는 것입니다. 이전에'GROUP_CONCAT'했기 때문입니다. 테이블 구조도를 올리 자마자 이걸 어떻게 처리 할 것인지 예를 보여 주시겠습니까? – Jacinto
오류 메시지를 복사 해 주시겠습니까? – Basti
신경 쓰지 말라 나는 바보이다, 나는 끝에 넣지 않았다. 좋아, 두 번째 부분은 작동하지만 여전히 1 개의 알코올, 1 개의 리뷰 및 1 명의 사용자 만 얻고 있습니다. 40 개의 알코올, 5 리뷰, 5 명의 사용자를 얻고 싶습니다. – Jacinto