我正在尝试使用 进行税收计算。税收计算所需的板或php
标准基于AGE
和。我正在使用框架。因为我是新手,所以我不知道如何完成这些事情。startincome
endincome
CODEIGNITER
我的代码应该只包含动态变量作为要从数据库中获取的“slabs”,并且应该根据随机给出的 AGE 和 Salary 生成结果。
我的视图文件如下:tax.php
<form>
<table border="1" align="center" cellpadding="30">
<tr>
<td colspan="2" align="center">
<b>Tax calculation</b>
</td>
</tr>
<tr>
<td>
<label for="name"><b>Name</label>
</td>
<td>
<input id="name" name="name" type="textbox" placeholder="enter your name" size="30" >
</td>
</tr>
<tr>
<td>
<label for="name"><b>Age</label>
</td>
<td>
<input id="name" name="name" type="textbox"placeholder="enter your age" size="30" >
</td>
</tr>
<tr>
<td>
<label for=""><b>Salary:</label></td>
<td>
<input id="salary" name="phone" type="textbox"placeholder="enter your yearly salary" size="30" >
</tr>
<tr>
<td>
<div>
<input type="submit" value="calculate" name="submit" />
</div>
</td>
<td>
<label for=""><strong>Tax Amount:</strong></label>
<input id="Tax" name="tax" type="textbox" size="17" >
</td>
</table>
</form>
我的控制器代码如下:Tax.php
<?php
class Tax extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
}
public function index()
{
$servername='localhost';
$username='root';
$password='';
$database='register';
$conn = mysqli_connect($servername,$username,$password);
$this->load->view('tax');
//$this->load->model(Taxmodel);
if(isset($_POST['submit']))
{
//echo"inside submit";
$this->form_validation->set_rules('name','Name','trim|required');
$this->form_validation->set_rules('age','Age','trim|required');
$this->form_validation->set_rules('salary','Salary','trim|required',array('required' => 'You must provide a %s.'));
//checks whether the validation returns true or false
if ($this->form_validation->run() ==TRUE)
{
//echo' validation check';
//storing data to Array
$userdata = array(
'Name' => $this->input->post('name'),
'Age' => $this->input->post('age'),
'Salary' => $this->input->post('salary')
);
print_r($userdata);
$this->load->model('Taxmodel');
//$this->Taxmodel->insertdata($userdata);
}
}
}
public function getresult()//to get database values in a row
{
echo "inside getresult";
$salary=$_POST['salary'];
$data= $this->db->query("SELECT * FROM `admin_income` WHERE age<".$age." and age in (SELECT max(age) FROM `admin_income` WHERE age<".$age." order by `age` desc) order by `age` desc ");
print_r($data);
$result=$conn->query($data);
Global $totaltax;
while ($row = mysql_fetch_assoc($result))
{echo "inside while1";
while($salary>= $row[$start_incom] && $salary< $row[$end_incom])
{
//echo"Inside tax calculation";
$diff=$salary-$startincome;
$tax=(($percentage/100)*$diff);
echo $tax;
}
echo $tax;
}
}
public function extamount()
{//to get the additional amount to be added
/*$query = $this->db->query("SELECT * FROM admin_income LIMIT 1;");
if ($query->num_rows() > 0)
{
$row = $query->next_row('array')*/
if($initial_income>$start_incom)//codnition for checking whether the salary exceeds first slab
{
$diffresult=$end_incom-$start_incom;
$adtntax=[($percentage/100)*$diffresult];
echo $adtntax;
}
$totaltax=$adtntax+$tax;
//}
}
}
?>
我的模型名称是 Taxmodel.php
我是 CodeIgniter 的新手。帮助将不胜感激。