• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need a clarification

#1
I am having one input item

when i submit the button two action should be taken

condition 
1, check with table1 if users already registered ,display the error message 'already Registered';
2, check with table2 if data available means Display the (name,phone) to the another screen else
    return error message 'Data not available';
I need clarity of my post. 

Controller
      $this->load->helper('url_helper');
          $this->load->library('form_validation');
          $regno = $this->input->post('regno');
          //echo $regno;
          $this->load->model('user_model');
          $result=$this->User_Model->check_alt_exists($regno);

          print_r($result);
          if($result>=1)
          {
          $this->load->library('session'); 
                $this->load->helper('url'); 

          $data['title'] = 'Registration';
          $this->session->set_flashdata('user_loggedin', 'Already Registered');
redirect('users/register1','refresh');
          $this->load->view('templates/header');
          //$this->load->view('users/register1',$data);
      $this->load->view('templates/footer');
          }
          else
          {
      echo "hai";
            } 


Model
****


public function check_alt_exists($regno){
$this->db->select('*');
  $this->db->from('users');
  $this->db->where('username',$regno);
  $query=$this->db->get();
 
  if($query->num_rows()>0){
    return true;
  }else{
    return false;
  }
}

I am struggled how to set 3 condition in one controller or written in another function should be called in this controller . Is it a good way..
Reply

#2
Just wondering: why do you keep pasting your php code and html as plain text in this forum?
On the toolbar of the editor, you have buttons for Code and for PHP. They surround your code by tags that make code much better readable. Please, use this buttons from now on.

About your code.
Your model returns true or false.
Your controller seems to be expecting a numeric value ( >= 1 ).

Change
PHP Code:
if($result>=1

into:
PHP Code:
if ($result)  //which is short for: if ($result == TRUE) 

Your model can be more efficient:
PHP Code:
/*
if ($query->num_rows()>0){
  return true;
}
else {
  return false;
}
*/
return ($query->num_rows() > 0) ;  //this wil return true if num_rows() is > 0, or false if it's not. 
Reply

#3
(09-07-2018, 07:17 AM)Wouter60 Wrote: Just wondering: why do you keep pasting your php code and html as plain text in this forum?
On the toolbar of the editor, you have buttons for Code and for PHP. They surround your code by tags that make code much better readable. Please, use this buttons from now on.

About your code.
Your model returns true or false.
Your controller seems to be expecting a numeric value ( >= 1 ).

Change
PHP Code:
if($result>=1

into:
PHP Code:
if ($result //which is short for: if ($result == TRUE) 

Your model can be more efficient:
PHP Code:
/*
if ($query->num_rows()>0){
  return true;
}
else {
  return false;
}
*/
return ($query->num_rows() > 0) ;  //this wil return true if num_rows() is > 0, or false if it's not. 

It 's working . thanks a lot .
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.