Welcome Guest, Not a member yet? Register   Sign In
conditional if statement on database query
#1

[eluser]andes[/eluser]
hi,

I am having trouble running a conditional if statement after running a database query. I want to match user input to existing records in a database, here is my code:

in the controller file
Code:
function create()
    {
        $data = array(
                    'gate' => $this->input->post('gate'),
                    'door' => $this->input->post('door')
                );
        
        $this->lex_model->add_records($data);
                
        $this->load->helper('array');
        
        $text1= element('gate', $data);
        $text2= element('door', $data);
        $tex = $text1;
        $tran = $text2;
        

        $goat['cow'] = $this->lex_model->shoeing($tex, $tran);
              
        
        if($data == $goat)
        {
            echo 'this is working';
        }
        else
        {
            echo 'this is NOT working';
        }
        
    }

in the model file
Code:
function shoeing($tex, $tran)
{

$query = $this->db->query("SELECT * FROM ques WHERE gate = '$tex'");
return $query->result_array();
            
        
}
Quote:the if($data == $goat) statement just doesn't seem to work. Can somebody please help with this, i can't seem to figure it out
#2

[eluser]InsiteFX[/eluser]
Code:
if($data == $goat['cow'])

InsiteFX
#3

[eluser]andes[/eluser]
I still doesn't work, I'm entering the same data as it exists in the database and the condition should be TRUE to give me the if part, 'this is working' rather than the else part. i've been stuck on this for so long now
#4

[eluser]InsiteFX[/eluser]
Code:
$data = array();

$this->db->where('gate', $tex);
$this->db->limit(1);
$query = $this->db->get('ques');

if ($query->num_rows() > 0)
{
    $data = $query->row_array();
}

$query->free_result();
return $data;

You can use var_dump to see what you are getting in your arrays!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB