[eluser]Unknown[/eluser]
hi everyone..
I've problem with grouping.
I have a MySQL table like this :
+----------+----------+----------+--------------+-------+-------+--------+
| type | id | name | address | bill |service| total |
+----------+----------+----------+--------------+-------+-------+--------+
|water |A1 |jhon |Samrat street |100 |50 |150 |
|electric |A1 |jhon |Samrat street |30 |15 |45 |
|electric |A2 |ana |zero street |20 |10 |30 |
|water |A3 |billy |west street |40 |60 |100 |
+----------+----------+----------+--------------+-------+-------+--------+
and I want to show table records in a letter (likes notification letter), like this:
jhon (A1)
Samrat street
+---------+-------+----------+---------+
|type |bill |service |total |
+---------+-------+----------+---------+
|water |100 |50 |150 |
|electric |30 |15 |45 |
+---------+-------+----------+---------+
| grand total|600 |
+----------------------------+---------+
ana (A2)
zero street
+---------+-------+----------+---------+
|type |bill |service |total |
+---------+-------+----------+---------+
|electric |20 |10 |30 |
+---------+-------+----------+---------+
| grand total|30 |
+----------------------------+---------+
billy (A3)
west street
+---------+-------+----------+---------+
|type |bill |service |total |
+---------+-------+----------+---------+
|water |40 |60 |100 |
+---------+-------+----------+---------+
| grand total|100 |
+----------------------------+---------+
I make the appearance by using FPDF and codeigniter, and here is my script:
model
Code:
function report($tgl)
{
return $this->db->query("select * from t_remletter where rem_date='$tgl'");
}
controller
Code:
function report()
{
$tgl = $this->session->userdata('tr');
$data['view'] = $this->m_srtpemb->report($tgl);
$this->load->view('srtpemb/report',$data);
}
view
Code:
foreach ($view->result() as $row){
$pdf->SetAutoPageBreak(true,10);
$pdf->Open();
$pdf->AddPage();
$nm = $row->name;
$add = $row->address;
$np = $row->id;
$tp = $row->type;
$sb = $row->bill;
$sr = $row->service;
$tot = $row->total;
//display name, id and address//
$pdf->SetFont('Times','B',12);
$pdf->Cell(100,5,"$nm ($np)",0,0,'L');
$pdf->Ln();
$pdf->SetFont('Times','',12);
$pdf->Cell(150,5,$add,0,0,'L');
$pdf->Ln(15);
//display header table//
$pdf->SetFont('Arial','',9);
$pdf->SetWidths(array(25,32,32,32));
$header=array('Type','Bill','Service','Total',);
$pos=array('C','C','C','C','C','C');
$pdf->Row($header,$pos);
//display detail records of table//
$pdf->Cell(25,5,$tp,'LRTB',0,'L');
$pdf->Cell(32,5,$sb,'LRTB',0,'R');
$pdf->Cell(32,5,$sr,'LRTB',0,'R');
$pdf->Cell(32,5,$tot,'LRTB',0,'R');
$pdf->Ln(10);
}
when I run this script, type of records that appear to jhon (A1), only water. I mean, there is no looping for the next record.
the problem is:
- how to make a loop to display the results as I have explained(I assume it was made in a web page, so the fpdf script can be ignored. but if you can fix it to the fpdf script, I would really appreciate it) and,
- how to create a script to calculate the grand total.
I hope somebody can help me to fix the script of looping process(view script)
Thanks..^_^