[英]CodeIgniter join table
This is my output // As you can see the Name is not the exact name 这是我的输出//如您所见,名称不是确切名称
And I found a code to solve this problem but I'm not really sure about which coding should I have to use. 我找到了解决该问题的代码,但是我不确定应该使用哪种编码。 Can you please help?
你能帮忙吗?
This is a set of function coding: 这是一组函数编码:
<?php
$rn= "0001123456";
$rn2= "A123456";
$dob = "1986-10-25";
$dreg = "1986-10-26";
echo "<br/>".$rn;
echo "<br/>".numberToAlpha($rn);
echo "<br/>".alphaToNumber($rn2);
echo "<br/>cur_age : ".calculateCurrentAge($dob);
echo "<br/>reg_age : ".calculateRegisterAge($dob, $dreg);
/*** End Contoh Penggunaan ***/
function numberToAlpha($rn)
{
if (strcmp('0000', substr($rn,0,4)) == 0) {
$rn = 'A'.substr($rn, 4, 6);
}else{
$rn = 'B'.substr($rn, 4, 6);
}
return $rn;
}
function alphaToNumber($rn)
{
if (strcmp('A', substr($rn,0,1)) == 0) {
$rn = '0000'.substr($rn, 1, 6);
}else{
$rn = '0001'.substr($rn, 1, 6);
}
return $rn;
}
function calculateCurrentAge($dob)
{
$from = DateTime::createFromFormat('Y-m-d', $dob);
$to = new DateTime('today +1 day');
$age = $from->diff($to);
return $age->format('%y years, %m months, %d days');
}
function calculateRegisterAge($dob, $dreg)
{
$from = DateTime::createFromFormat('Y-m-d', $dob);
$to = DateTime::createFromFormat('Y-m-d', $dreg);
$to = $to->modify('+1 day');
$age = $from->diff($to);
return $age->format('%y years, %m months, %d days');
}
Can you tell me if I want to change the Name to a proper Name which coding should I use and where to add these coding? 您能告诉我是否要将名称更改为专有名称,我应该使用哪种编码以及在何处添加这些编码?
This is my controllers 'Search.php': 这是我的控制器“ Search.php”:
<?php
class Search extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('form');
$this->load->model('Search_model');
}
public function index()
{
$this->load->view('search_form');
}
public function execute_search()
{
// Retrieve the posted search term.
$search_term = $this->input->post('search');
// Use a model to retrieve the results.
$data['results'] = $this->Search_model->get_results($search_term);
// Pass the results to the view.
$this->load->view('search_results',$data);
}
}
This is model 'Search_model.php': 这是模型“ Search_model.php”:
<?php
class Search_model extends CI_Model {
public function get_results($search_term='default')
{
// Use the Active Record class for safer queries.
$this->db->select('rn,nama,tarikhlahir,jantina,agama,bangsa');
$this->db->from('pesakit');
$this->db->like('rn',$search_term);
$this->db->limit(100);
// Execute the query.
$query = $this->db->get();
// Return the results.
return $query->result_array();
}
}
This is views for search 'search_form.php': 这是搜索“ search_form.php”的视图:
<?php
echo form_open('search/execute_search');
echo form_input(array('name'=>'search'));
echo form_submit('search_submit','Submit');
?>
This is results views 'search_results.php': 这是结果视图“ search_results.php”:
<div>
<?php
// List up all results.
foreach ($results as $val)
{
echo 'RN : '; echo $val['rn']; echo "<br/>";
echo 'Name : '; echo $val['nama']; echo "<br/>";
echo 'Date.of.Birth : '; echo $val['tarikhlahir']; echo "<br/>";
echo 'Gender : '; echo $val['jantina']; echo "<br/>";
echo 'Race : '; echo $val['bangsa']; echo "<br/>";
echo 'Religion : '; echo $val['agama'];
}
?>
</div>
I can see an error in your model 我可以看到您的模型有错误
Please replace 请更换
$this->db->select('jantina','bangsa','agama');
With 用
$this->db->select('jantina,bangsa,agama');
And in your view 在您看来
<div>
<?php
// List up all results.
foreach ($results as $val)
{
echo $val['jantina'].'<br>';
echo $val['bangsa'].'<br>';
echo $val['agama'];
}
?>
</div>
You might echo it in the view page. 您可以在视图页面中回显它。
<div>
<?php
// List up all results.
foreach ($results as $val)
{
echo $val['jantina']; echo ',';
echo $val['bangsa']; echo ',';
echo $val['agama'];
}
?>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.