Query SQL does not work correctly

Asked

Viewed 56 times

0

Good Afternoon,

I’m trying to pull existing hour intervals on my bench.

I’ll post the codes to be more explanatory

Query:

    $user = "Diego";
    $pack = "0013-001 B515 MCA ENGINEERING SUPPORT SYSTEM";
    $date = "20-09-2019";
    $horai = "14:01";
    $horaf = "14:03";

         $sql = $this->db->select('hrStart, hrEnd, hdate, pacote')
                    ->from('horas')
                    ->where('hrStart<=',$horai)
                    ->where('hrEnd>=',$horaf)
                    ->or_where('hrStart<=',$horaf)
                    ->where('hrEnd>=',$horai)
                    ->where(array('nome_user LIKE'=> '%'.$user.'%', 'pacote'=>$pack, 'hdate'=>$date, ))
                    ->get();
    return $sql;

My bank:

BD

The Return:

![Retorno

Note that in the return it brings information from another package when I put this interval of 14:00 - 14:03 or other intervals where the numbers are between existing times, and the same interval does not exist.

  • 1

    If you want an interval between start time and end time, remove this or_where and the Where just below, it didn’t make much sense to me. Now if you have an applied logic behind this you should group or_where and Where eguinte, I don’t know how to do in codeigniter but this will break the logic if you don’t do the grouping.

1 answer

0

I used the function group_start();

            $sql = $this->db->select('hrStart, hrEnd, hdate, pacote')
            ->from('horas')
            ->group_start()
            ->where('hrStart<=',$horai)
            ->where('hrEnd>=',$horaf)
            ->or_group_start()
            ->where('hrStart<=',$horaf)
            ->where('hrEnd>=',$horai)
            ->group_end()
            ->group_end()
            ->where(array('nome_user LIKE'=> '%'.$user[0].'%', 'pacote'=>$pack, 'hdate'=>$date, ))
            ->get();
    return $sql;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.