if($records->result()>0)
{
foreach ($records->result() as $user)
{
$username= ('first name='.$user->u_first_name.'<br/>'.'Last name='.$user->u_last_name.'<br/>'.'Email='.$user->u_email.'<br/>'.'Property Id='.$user->propertyid);
$username.="<br/>";
$username.="-------------------------";
$username.="<br/>";
$email_template = file_get_contents($this->config->item('base_url').'assets/email/email.html');
$email_template = str_replace("[[EMAIL_HEADING]]", $mail_content->subject, $email_template);
$email_template = str_replace("[[EMAIL_CONTENT]]", $username, $email_template);
$email_template = str_replace("[[SITEROOT]]", $this->config->item('base_url'), $email_template);
$email_template = str_replace("[[LOGO]]",$this->config->item('base_url')."assets", $email_template);
$this->email->message(html_entity_decode($email_template));
$this->email->send();
print_r($email_template);
this is my code
/* UPDATE */
You can use a view for your template like normal (passing in values), setting the third parameter as TRUE to return the html.
To send one email with all database records, just pass the entire result object into the view, the process it in the view using your standard foreach loops, etc..
E.g
if($records->result()>0) {
$email_template = $this->load->view('email_template', array('heading' => 'My Email Report', 'records' => $records->result(), TRUE);
$this->email->message($email_template);
$this->email->send();
print_r($email_template);
}
Then the view (/view/email_template) would be something like;
<h1><?php echo $heading; ?>
<p> Records;</p>
<table>
<?php
foreach ($records as $r) {
?>
<tr>
<td><?php echo $r->u_first_name; ?></td>
<td><?php echo $r->u_last_name; ?></td>
<td><?php echo $r->u_email; ?></td>
<td><?php echo $r->propertyid; ?></td>
</tr>
<?php
}
?>
</table>
Related
im trying to learn,
here the file when im downloading
here the script im using
controller
function get_file(){
$id=$this->uri->segment(3);
$get_db=$this->m_dpks->get_file_byid($id);
$q=$get_db->row_array();
$file=$q['file_data'];
$path='./assets/dpks/'.$file;
$data = file_get_contents($path);
$name = $file;
force_download($name, $data);
}
here the view
<?php
$query = $this->db->query("SELECT * FROM tbl_dpks;");
$no=1;
foreach ($query->result() as $row):
?>
<tr>
<td><?php echo $no++;?></td>
<td><?php echo $row->file_judul;?></td>
<td><?php echo $row->file_deskripsi;?></td>
<td><?php echo $row->file_oleh;?></td>
<td style="text-align:right;">Download</td>
</tr>
<?php endforeach;?>
appreciate for help,
I want to ask about view
here I have controller like this: (api.php)
public function export_excel() {
$date = new DateTime($this->input->post('date_fil'));
$curr_date = $date->format('Y-m-d ');
$user = $this->input->post('sales_name');
$checked = $this->input->post('cb_month');
$month = date('m');
if ((int) $checked == 1) {
$this->form_validation->set_rules('sales_name', 'Sales Name', 'required');
if ($this->form_validation->run() == false) {
$this->output->set_output(json_encode([
'result' => 0,
'error' => $this->form_validation->error_array()
]));
return false;
}
$this->db->select('t1.act_id, t2.login, t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
->from('activity as t1')
->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
->where('t2.login', $user)
->where('MONTH(t1.date_added)', $month);
$query = $this->db->get();
$result = $query->result_array();
$data = array('title' => 'Sales Report',
'user' => $result);
$this->load->view('report/vw_excel', $data);
// Selecting data by Date ----------------------------------------------
} else {
$this->form_validation->set_rules('sales_name', 'Sales Name', 'required');
$this->form_validation->set_rules('date_fil', 'Date', 'required');
if ($this->form_validation->run() == false) {
$this->output->set_output(json_encode([
'result' => 0,
'error' => $this->form_validation->error_array()
]));
return false;
}
$this->db->select('t1.act_id, t2.login, t1.cust_name, t1.act_type, t1.act_detail, t1.date_added, t1.date_modified, t1.act_notes')
->from('activity as t1')
->join('user as t2', 't1.user_id = t2.user_id', 'LEFT')
->where('t2.login', $user)
->where('DATE(t1.date_added)', $curr_date);
$query = $this->db->get();
$result = $query->result_array();
$data = array('title' => 'Sales Report',
'user' => $result);
$this->load->view('report/vw_excel', $data);
}
and here's the view I want to load it's under folder (report/vw_excel)
<body>
<main>
<h1>Excel Report</h1>
<p>Export to Excel</p>
<table border="1" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Sales Name</th>
<th>Customer Name</th>
<th>Activity</th>
<th>Detail</th>
<th>Start Time</th>
<th>Finish Time</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach($user as $xuser) { ?>
<tr>
<td><?php echo $xuser['act_id']; ?></td>
<td><?php echo $xuser['login']; ?></td>
<td><?php echo $xuser['cust_name']; ?></td>
<td><?php echo $xuser['act_type']; ?></td>
<td><?php echo $xuser['act_detail']; ?></td>
<td><?php echo $xuser['date_added']; ?></td>
<td><?php echo $xuser['date_modified']; ?></td>
<td><?php echo $xuser['act_notes']; ?></td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</main>
when I call it from other view folder(admin/admin_view)
onsubmit = 'api/export_excel',
this "$this->load->view('report/vw_excel', $data);" wont load the view.
the result are showing in the browser's network, but the view doesn't load.
network view
any idea? thanks.
Do a right click on the screen - inspect element. In the elements panel, select the table that was supposed to be there on screen. Check in the Style panel if the same is not turned off from being displayed for some reason.
You may also check its position (if in case it is visible) on screen for you to be able to diagnose whether the element is actually in screen dimensions.
my model function is
public function getUser()
{
$this->db->select(array('customer_name','customer_address','phone_no','fax','email_id','contact_person_name','mobile_no'));
$this->db->from('add_customer');
$this->db->where(array('status'=>1));
$res = $this->db->get();
if($res->num_rows() > 0)
{
$rows = $res->result_array();
return $rows;
}else{
return false;
}
}
function in controller
public function search_customer()
{
//$this->load->helper('url');
$data['baseurl'] = base_url();
$this->load->view('templates/header');
$data['details'] = $this->Customer_model->getUser();
$this->load->view('master/customer',$data);
}
data extracting from my view is like this
<?php for($i=0;$i<count($details);$i++){ ?>
<tr>
<td><?php echo ($i+1); ?></td>
<td><?php echo $details[$i]['customer_name']; ?></td>
<td><?php echo $details[$i]['customer_address']; ?></td>
<td><?php echo $details[$i]['phone_no']; ?></td>
<td><?php echo $details[$i]['email_id']; ?></td>
<td><?php echo $details[$i]['contact_person_name']; ?></td>
<?php }?>
and this one results in an error like this
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: details
Filename: master/Customer.php
Line Number: 69
anybody please tell me why this error is getting
try to load your model in your controller like
$this->load->model('Customer_model');
without loading your model you con't get the details from get_user function
Model:
public function getUser()
{
$this->db->select('customer_name','customer_address','phone_no',
'fax','email_id','contact_person_name','mobile_no');
$this->db->from('add_customer');
$this->db->where('status',1);
return $this->db->get()->result();
}
Controller:
public function search_customer()
{
$data['baseurl'] = base_url();
//Load the view in variable as data, but do not render
//($header is accessible in 'master/customer' view)
$data['header'] = $this->load->view('templates/header','',true);
//Be sure to load Customer_model
$data['details'] = $this->Customer_model->getUser();
$this->load->view('master/customer',$data);
}
View:
<?php if(count($details)): ?>
<?php foreach($details as $detail): ?>
<tr>
<td><?php echo $detail->customer_name; ?></td>
<td><?php echo $detail->customer_address; ?></td>
<td><?php echo $detail->phone_no; ?></td>
<td><?php echo $detail->email_id; ?></td>
<td><?php echo $detail->contact_person_name; ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
try using $data instead of $details in your master/Customer.
I want to export data in my MYSQL Database into a DOC file using Codeigniter.
My code is as follows:
view named 'profile_top_view.php' where anchor is declared as :
<?php echo anchor('welcome/todoc','Export Posts to DOC File') ?>
controller named 'welcome.php' has function :
public function todoc() {
$id = $this->tank_auth->get_user_id();
$this->mpdf->useOnlyCoreFonts = true;
$filename = "POSTS";
$data['member'] = $this->s_model->alldata($id);
$this->load->view('export_posts_doc_view', $data, true);
$this->index();
}
A view named 'export_posts_doc_view.php', where a table will be created for the DOC file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Exported Posts in PDF File</title>
</head>
<body>
<?php
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-disposition: attachment; filename=\"posts.doc\"");
?>
<div id="container">
<h4>Posts</h4>
<table border="1">
<tr>
<th>title</th>
<th>content</th>
<th>group</th>
<th>video_url</th>
<th>pic_path</th>
<th>name</th>
<th>phone</th>
<th>email</th>
<th>yes_no</th>
<th>single-line-text</th>
<th>para_text</th>
<th>pdf_file_name</th>
<th>add_photo_name</th>
</tr>
<?php
foreach ($member as $rows) {
?>
<tr>
<td><?php echo $rows['title'] ?></td>
<td><?php echo $rows['content'] ?></td>
<td><?php echo $rows['group'] ?></td>
<td><?php echo $rows['video_url'] ?></td>
<td><?php echo $rows['pic_path'] ?></td>
<td><?php echo $rows['name'] ?></td>
<td><?php echo $rows['phone'] ?></td>
<td><?php echo $rows['email'] ?></td>
<td><?php echo $rows['yes_no'] ?></td>
<td><?php echo $rows['single-line-text'] ?></td>
<td><?php echo $rows['para_text'] ?></td>
<td><?php echo $rows['pdf_file_name'] ?></td>
<td><?php echo $rows['add_photo_name'] ?></td>
</tr>
<?php
}
?>
</table>
<br> <br>
</div>
</body>
</html>
and also a model named 's_model.php', having function :
function alldata($id)
{
$this->db->select('');
$this->db->from('posts');
$this->db->where('user-id',$id);
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
}
If I keep that header there, then it is showing error as:
No webpage was found for the web address:
http://www.my_ip.com/project/welcome/todoc
But, if I remove the same header, it shows the things echoed in the controller.
I have got that header from the following URL:
exporting MS word documents using codeigniter?
Can anyone please let me know what should I do with that?
Thanks in advance..
Got the answer,
I made few changes in my controller 'welcome.php':
public function todoc() {
$id = $this->tank_auth->get_user_id();
$this->mpdf->useOnlyCoreFonts = true;
$filename = "POSTS";
$data['member'] = $this->s_model->alldata($id);
$this->load->view('export_posts_doc_view', $data);
}
see the code below i hope i will work for you
function exportexcel()
{
header("Content-type: application/vnd.ms-excel");
/* change the content-type depends upon our requerment */
header("Content-Disposition: attachment; filename=Sadhak.xls");
header("Pragma: no-cache");
header("Expires: 0");
$table = "your content goes here";
echo $table;
}
I am trying to display information from database. I have set $config['per_page'] to 2, in my view file I can see the information I want but when I click on the next button it doesn't change anything. The database values remain same and the current page remains the first page too.
Would you please kindly help me figure out the problem?
Thanks in Advance :)
Controller:
function index($id){
$this->load->library('pagination');
$config['base_url'] = site_url().'Student_fee_status/index/'.$id;
$this->db->select('*');
$this->db->from('studentpayment1');
$this->db->where('studentid', $id);
$query = $this->db->get('');
$numrows=$query->num_rows();
$config['total_rows'] = $numrows;
$config['per_page'] = 2;
$config['uri_segment'] = '2';
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('Mod_student_fee_status');
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
$data['main_content']='view_student_fee_status';
$this->load->view('includes/template',$data);
}
My Model :
function fee_status($id,$perPage,$uri_segment) {
$this->db->select('*');
$this->db->from('studentpayment1');
$this->db->where('studentid', $id);
$getData = $this->db->get('', $perPage, $uri_segment);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
EDIT
When the page first loads the link looks like this- http://localhost/sundial/Student_fee_status/index/1006/
but when I click on the next page it looks like this- http://localhost/sundial/Student_fee_status/index/1006/2
My View File:
<h1>Payment Status</h1>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>S.N</th>
<th>Invoice ID</th>
<th>Transaction Description</th>
<th>Received Date</th>
<th>Debit</th>
<th>Credit</th>
<th>Balance</th>
</tr>
</thead>
<?php $i = $this->uri->segment(2) + 0; foreach ($records as $row){ $i++; ?>
<tbody>
<?php
$mydate= $row['period'];
$month = date("F",strtotime($mydate));
$year = date("Y",strtotime($mydate));
?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['invoiceid'];?></td>
<td><a href="<?php echo base_url(); ?>student_fee_status/fee_types/<?php echo $row['paymentid']; ?>" rel="1" class="newWindow" >Total Fee For <?php echo $month ;?>, <?php echo $year ;?> </a></td>
<td><?php echo $row['received_date'];?></td>
<td><?php echo $row['totalamount'];?></td>
<td><?php echo "0";?></td>
<td><?php echo $row['totalamount'];?></td>
</tr>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['invoiceid'];?></td>
<td>Payment Received </td>
<td><?php echo $row['received_date'];?></td>
<td><?php echo "0";?></td>
<td><?php echo $row['amountpaid'];?></td>
<td>
<?php
$balance=$row['totalamount']-$row['amountpaid'];
if($balance>0){
echo "<font color=\"red\">$balance</font>";
}
else {
echo $balance;
}
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
You are telling the pagination library to use $config['uri_segment'] = '2'; - the second segment of your uri.
When this is your url: http://localhost/sundial/Student_fee_status/index/1006/ I am guessing this is your base_url: http://localhost/sundial/
In this case your segments are:
Student_fee_status - your controller
index - the controllers method you are calling
1006 - the argument you are calling the controllers method with
this should be the argument for pagination
Try this
$config['uri_segment'] = '4';
instead of
$config['uri_segment'] = '2';
edit:
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
I think this line contains another error.
You pass your model the information which uri_segment is used by the pagination library. That should be 4 now. However, your model uses this value to specify an offset in your query. This means you always put an offset of 4 into your query. But I think what you really want to do is, pass the model the VALUE of the 4th uri_segment.
I would try this instead:
$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$this->uri->segment($config['uri_segment']));