こんにちは私はすでに他の質問でこれを研究しましたが、私は答えを得ていないので、ここで質問することにしました。あなたが私を助けてくれることを願っています。私はtblDataに、私は人の名前を格納していますし、何もちろん、彼らが取っている間、私はtblCourseに私のコースリストのすべてを格納されており、tblCourseとtblDataある2つのテーブルを持っている毎月のデータを集計
: はここで質問/問題です。今、私がしたいのは、毎月特定のコースを受講している人の総数を取得したいのです。例については
:
----------------------------------------------------------------------------
Course | Jan | feb | Mar | Apr | May | ......................| Dec | Total |
----------------------------------------------------------------------------
Course1 | 2 | 3 | 0 | 0 | 1 | ......................| 2 | 8 |
----------------------------------------------------------------------------
Course2 | 2 | 3 | 2 | 0 | 1 | ......................| 2 | 10 |
----------------------------------------------------------------------------
Course3 | 2 | 3 | 1 | 0 | 1 | ......................| 2 | 9 |
----------------------------------------------------------------------------
ここに私のコードです:
<?php
$query = $this->db->query("SELECT * FROM tblcourse where category = 'Soft' and inex = 'inhouse' ORDER by course_name ASC");
foreach ($query->result() as $row){
?>
<tr>
<td>Id</td>
<td><?php echo $row->course_name; ?></td> // Output the Course Name
<td class="center"><?php echo $row->days; ?></td> //Output the Training days
<?php
$course = $row->course_name;
$query_jan = $this->db->query("SELECT * FROM tbldata where course like '%$course%' and course_end < '2016-11-30' and course_end >= '2016-11-01'");
?>
<td><?php echo $query_jan->num_rows(); ?></td> // Output the corresponding number of course taken by the person for the month of january
<? php
} // end of foreach
?>
相続人は私のデータベースの構造:男はあなたが私を助けることができると思います
Table 1: tblCourse
Fields: ID, Course_name, Category, Training_days
Table 2: tblData
Fields: ID, Trainees_name, Course_taken, Date_start, Date_end
ありがとう!
私の初心者のコードのため申し訳ありませんが、私はPHPを使用して開発し始めている。..
EDIT:Guysは、私は単一のクエリでこれを照会することができますか?そうであれば?親切に私にどのように表示できますか?ありがとうございました!
「tblCourse」と「tblData」の関係は何ですか?関係があれば、SQL-JOINを実行して、必要な結果を得ることができます。 – Poiz
私にはどのように表示できますか? course_takenがtbldataからの外部キーであると仮定します – zeus2026