• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems using "where"and "like" together . . .

#1
[eluser]blorriman[/eluser]
I'm trying to find a keyword ($keywords) in 2 different fields of the same table, but I need to join the table with another one to get more info, but when I try to use a where statement for the group_id it seems to ignore it. Here's the code :
Code:
function topics($keywords) {
        $query = $this->DB2->query("SELECT
            meetings.startdate,
            agendas.topic,
            agendas.preamble,
            meetings.group_id,
            agendas.mtg_id
            FROM
            agendas
            Inner Join meetings ON agendas.mtg_id = meetings.id
            WHERE
            agendas.topic LIKE  '%" . $keywords . "%' OR
            agendas.preamble LIKE  '%" . $keywords . "%' AND
            meetings.group_id =  " . $this->group_id . "");
        return $query;
    }

Any suggestions would be greatly appreciated - Thanks.

#2
[eluser]blorriman[/eluser]
Solved - the LIKE operators need to be in brackets :
Code:
function topics($keywords) {
        $query = $this->DB2->query("SELECT
        meetings.group_id,
        agendas.topic,
        agendas.preamble,
        meetings.startdate,
        agendas.mtg_id
        FROM
        agendas
        Inner Join meetings ON agendas.mtg_id = meetings.id
        WHERE
        meetings.group_id =  '" . $this->group_id . "' AND
        (agendas.topic LIKE  '%" . $keywords . "%' OR
        agendas.preamble LIKE  '%" . $keywords . "%')
        ");
        return $query;
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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