Jump to content

MySql Base help - Codeigniter


skemi90

Recommended Posts

Hello,

 

I am new to php and I am stuck with this problem.

I have in my mysql base a table (table1) with three columns A, B and C (for easy explanation).

 

 id   A      B        C

 1   60    200     4

 2   40    100     3

 ...  ...      ...       ...

Table has more than 500 combinations.

 

I created two input fields on my index page for column A and B. C column is a result.

 

Problem is to code next:

When someone enters 60 and 200 in those two input fields I want to generate an automatic result 4, for 40 and 100 result 3 and so on.

 

I am using codeigniter framework. If it is needed you can split above table to three tables A, B and C.

Thanks in advance and sorry for my bad english,

please don't hesitate to ask questions.

Link to comment
https://forums.phpfreaks.com/topic/296279-mysql-base-help-codeigniter/
Share on other sites

Model 

    public function GET($input1, $input2){

        $this->db->select('c');
        $this->db->from('table1');
        $this->db->where('A', $input1);
        $this->db->where('B', $input2);

        $query = $this->db->get();
        return $query;
    }

Controller

public function get_result()
    {
        //validation rules

        $this->form_validation->set_rules('a', 'A', 'trim|required');
        $this->form_validation->set_rules('b', 'B', 'trim|required');

        if ($this->form_validation->run() == FALSE) {

            $this->load->view('admin/dashboard/inc/header');
            $this->load->view('admin/procena/index');
            $this->load->view('admin/dashboard/inc/footer');
        } else {

            $input1 = $this->input->post('A');
            $input2 = $this->input->post('B');

                $result = $this->ModelABC_model->GET($input1,$input2);
                echo $result;

                /*redirect('admin/index');*/

        }
    }
At least now I'm going in a certain direction, I think I understand your logic but now I have a new problem. 
 

I get an error "could not be converted to string"

 

Thank you for your rapid response.

This topic is SOLVED!

 

I was loking a way to mark it by myself, but without luck.  ::)

 

Please, can any moderator mark this topic as SOLVED?

There is a "Mark Solved" button on the lower-right of each post. Click that next to the post that was most helpful.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.