0

私はcodeigniterを使用し、データを表示するためのクエリモデルを持っています

function get_accfotografer(){
        $sql="SELECT
  `artikel`.`foto_naam`,
  `fotografer`.`id` AS 'fotografer_id',
  `customer`.`id` AS 'customer_id',
  `fotografer`.`name_fotografer`,
  `customer`.`first_name`,
  `customer`.`last_name`,
  `fotografer`.`domain_name`,
  `fotografer`.`email`,
  `order`.`invoice_no`,
  `order`.`order_cost`,
  `order`.`total_cost`,
  `order`.`invoice_date`,
  `order`.`payment`,
  `order`.`status`
FROM
  `artikel_group`
  INNER JOIN `artikel` ON `artikel`.`artikelgroup_id` = `artikel_group`.`id`
  INNER JOIN `fotografer` ON `artikel_group`.`fotografer_id` = `fotografer`.`id`
  INNER JOIN `order_has_artikelgroup` ON `order_has_artikelgroup`.`artikelgroup_id` = `artikel_group`.`id`
  INNER JOIN `order` ON `order`.`id` = `order_has_artikelgroup`.`order_id` 
  INNER JOIN `customer` ON `order`.`customer_id` = `customer`.`id`
";
        $row=$this->db->query($sql);
        return $row;
      }

次に、コントローラーでコードを使用しました

$data['accphotografer'] = $this->M_admin->get_accfotografer()->result();

ビューで

        <?php foreach ($accphotografer as $data) { ?>
            <tbody>
                <tr>
                    <td><?php echo $no; ?></td>
                    <td><?php echo $data->name_fotografer ?></td>
                    <td><?php echo $data->email ?></td>
                    <td><?php echo $data->domain_name ?></td>
                    <td><?php echo $data->first_name ?> <?php echo $data->last_name ?></td>
                    <td><?php echo $data->foto_naam ?></td>
                    <td><?php echo $data->invoice_no ?></td>
                    <td><?php echo $data->invoice_date ?></td>
                    <td><?php echo $data->order_cost ?></td>
                    <td><?php echo $data->total_cost ?></td>
                    <td><?php echo $data->payment ?></td>
                    <td><?php echo $data->status ?></td>
                    <td>
                    <?php echo anchor('admin/order_delete/' . $data->fotografer_id, 'Delete', array('class' => 'delete', 'onclick' => "return confirm('you sure delete?')")); ?></td>
                </tr>
            </tbody>

            <?php $no = $no + 1; ?>
        <?php } ?>
    </table>

例の結果は

1   lekto   jhon@yahoo.com  www.jhon.com    Romualdus Bimantara Pre-School_Child.jpg
dp-0413-000027  2013-04-26  200.00  0.00    contant paid    Delete
2   lekto   jhon@yahoo.com  www.jhon.com    dinda sari  Pre-School_Child.jpg
dp-0413-000028  2013-04-26  145.00  0.00    contant paid    Delete
3   lekto   jhon@yahoo.com  www.jhon.com    lugas hakim Pre-School_Child.jpg
dp-0513-000030  2013-05-03  104.00  0.00    contant paid    Delete
4   lekto   jhon@yahoo.com  www.jhon.com    lugas hakim Pre-School_Child.jpg
dp-0513-000032  2013-05-03  224.00  0.00    contant paid    Delete

私の質問は、データが同じ例である場合に1つのデータを表示する方法です

name   | email           | customer | invoice no
lekto  |  jhon@gmail.com | dinda sari| 001
       |                 |           | 002
       |                 | lugas     | 012
jhon   | jsn@gmail.com   | dinda     | 013

この問題を解決するのを手伝ってください

4

1 に答える 1

0

次のように GROUP BY を使用できます。

$sql="SELECT
  `artikel`.`foto_naam`,
  `fotografer`.`id` AS 'fotografer_id',
  `customer`.`id` AS 'customer_id',
  `fotografer`.`name_fotografer`,
  `customer`.`first_name`,
  `customer`.`last_name`,
  `fotografer`.`domain_name`,
  `fotografer`.`email`,
  `order`.`invoice_no`,
  `order`.`order_cost`,
  `order`.`total_cost`,
  `order`.`invoice_date`,
  `order`.`payment`,
  `order`.`status`
FROM
  `artikel_group`
  INNER JOIN `artikel` ON `artikel`.`artikelgroup_id` = `artikel_group`.`id`
  INNER JOIN `fotografer` ON `artikel_group`.`fotografer_id` = `fotografer`.`id`
  INNER JOIN `order_has_artikelgroup` ON `order_has_artikelgroup`.`artikelgroup_id` = `artikel_group`.`id`
  INNER JOIN `order` ON `order`.`id` = `order_has_artikelgroup`.`order_id` 
  INNER JOIN `customer` ON `order`.`customer_id` = `customer`.`id`
  GROUP BY `fotografer`.`email`
";
于 2013-05-07T03:19:56.237 に答える