I have a function that i'm trying to use to pass arguments
This is the function which decides the option sql that is executed
function search_choice($choice, $fieldname)
{
$choice = $choice;
$fieldname = $fieldname;
if ($this->record_status == "active")
{
$query = $this->db->query("SELECT customer_type_id, customer_type, record_status FROM customer_type WHERE '$fieldname' = '$choice' AND record_status ='active' ");
}
else if ($this->record_status == "inactive")
{
$query = $this->db->query("SELECT customer_type_id, customer_type, record_status FROM customer_type WHERE '$fieldname' = '$choice' AND record_status ='inactive' ");
}
else
{
$query = $this->db->query("SELECT customer_type_id, customer_type, record_status FROM customer_type");
}
return $query;
}
This is the function that sets the variable values and then calls the function at the top
function search_customertype()
{
$this->customer_type_id = $this->input->post('customer_type_id');
$this->customer_type = $this->input->post('customer_type');
$this->record_status = $this->input->post('record_status');
$fieldname = "customer_type";
$rec_status = $this->record_status;
if ( !( $this->input->post('customer_type_id')))
{
$choice = $this->customer_type;
$fieldname = "customer_type";
$query = $this->search_choice($choice, $fieldname);
}
else
{
$choice = $this->customer_type_id;
$fieldname = "customer_type_id";
$query = $this->search_choice($choice, $fieldname);
}
$query;
return $query;
}
The problem is when i run the query in the form as shown below
<label>Customer Type ID
<input type="text" name="customer_type_id">
</label>
<p>
<label>Customer Type
<input name="customer_type" type="text" size="27">
</label>
</p>
<p>
<label>Record Status:
<select name="record_status" >
<option value="">Any Status</option>
<option value="active">Active</option>
<option value="inactive">Inactive</option>
<option value="">Active and Inactive</option>
</select>
</label>
</p>
I don't get the expected output. When i enter Customer type id or Customertype, no value is returned. What's wrong in the above code?