관리자가 작성한 주문을 볼 수있는 PHP 애플리케이션을 구축 중입니다.날짜별로 월별 헤드 라인 정렬
는 지금 목록은 다음과 같습니다
Orders
------
User Date Num Show Details Delete
..........................................................................
User 1 2013-05-24 20:41 4 x x
User 2 2013-05-12 15:46 5 x x
User 3 2013-04-24 20:41 8 x x
User 4 2013-04-03 20:41 1 x x
User 5 2013-03-20 20:41 6 x x
나는 그것을보고 싶지 방법 :
Orders
------
May 2013
User Date Num Show Details Delete
..........................................................................
User 1 2013-05-24 20:41 4 x x
User 2 2013-05-12 15:46 5 x x
April 2013
User Date Num Show Details Delete
..........................................................................
User 3 2013-04-24 20:41 8 x x
User 4 2013-04-03 20:41 1 x x
March 2013
User Date Num Show Details Delete
..........................................................................
User 5 2013-03-20 20:41 6 x x
데이터는 현재 날짜, 오름차순으로 정렬 된 DB에서 선택되고있다.
나는 12 개의 다른 DB 호출과 12 개의 테이블을 만들 수 있다는 것을 알고 있지만 어떻게 든 더 똑똑해질 수 있는지 궁금해하고 있었습니까?
저는 프레임 워크로 CodeIgniter를 사용하고 있습니다. ..
는 스크립트는 루프에서 실행 것으로 보인다
업데이트, 그리고 왜하지 않는 뷰 파일의
중요한 비트 :
<div class="row-fluid">
<div class="span8 offset2">
<?php
$lastGroup = ""; // this is how we are going to keep track of what month we are in
echo "output the report header";
while($row = $orders2->next_row('array')){
if ($lastGroup != $row['group_name']){
if ($lastGroup != ""){
echo "output footer from previous section";
}
echo "output header for new group";
}
echo "output the row";
// update the last group variable
$lastGroup = $row['group_name'];
}
echo "output the last group footer";
echo "output the report footer";
?>
</div>
</div>
컨트롤러 파일의 중요한 비트 :
$data['orders2'] = $this->manage_model->getallorders2();
모델 파일의 중요한 비트 :
function getallorders2()
{
$this->db->select("CONCAT(UCASE(LEFT(date_format(date, '%M %Y'),1)), SUBSTRING(date_format(date, '%M %Y'),2)) group_name, user_id, date, order_id", FALSE);
$this->db->from('orders');
$this->db->group_by('user_id, date');
$this->db->order_by('date desc');
return $this->db->get();
}
을 따를 수
같은 시도 배열과 달에 따라 배열에 출력, 그 결과를 에코 네가 원하는 곳? – gtr1971
@ gtr1971 : 나는 그 코드를 실제로 잡아 내지 못했습니다. 몇 가지 예제 코드를 보여줄 수 있습니까? –
당신은 또한 당신의 SQL 문에서 GROUP BY를 원할 것입니다. CI가 허용 할 것이기 때문에, 당신은 호출 된/호출하는 방식을 사용할 필요가 없습니다. – dmayo