Welcome Guest, Not a member yet? Register   Sign In
Help needed with search query
#5

[eluser]Bus Pants[/eluser]
Yeah good catch... so it only appears to be working against the models.model column...

If I type "Camry" in the search box I get 7 results... if I type "Camry DOHC" or just "DOHC" where the "DOHC" part would be found in the engines.engine column, I get no results... since it is an OR between them, all 7 of the Camry results should still show up, right?

The CI Code

Code:
$terms = explode(' ', trim($search_term));
$terms = implode("','", $terms);
$terms = "'" . $terms . "'";

$this->db->select('engines.*, models.model as model_name, makes.make as make_name');
$this->db->from('engines');

$this->db->where("(`engines`.`status` = 1) AND (`models`.`model` IN ($terms)
OR `engines`.`engine` IN ($terms))");

$this->db->join('models', 'models.id = engines.model');
$this->db->join('makes', 'makes.id = engines.make');
$this->db->order_by('makes.make, models.model, engines.first_year', 'ASC');


RAW Query I get when I search for "Camry" (shows 7 results)

Code:
SELECT `engines`.*, `models`.`model` as model_name, `makes`.`make` as make_name
FROM (`engines`)
JOIN `models` ON `models`.`id` = `engines`.`model`
JOIN `makes` ON `makes`.`id` = `engines`.`make`

WHERE (`engines`.`status` = 1) AND (`models`.`model` IN ('Camry') OR `engines`.`engine` IN ('Camry'))

ORDER BY `makes`.`make`, `models`.`model`, `engines`.`first_year` ASC


RAW Query I get when i search for "Camry DOHC" (shows no results)

Code:
SELECT `engines`.*, `models`.`model` as model_name, `makes`.`make` as make_name
FROM (`engines`)
JOIN `models` ON `models`.`id` = `engines`.`model`
JOIN `makes` ON `makes`.`id` = `engines`.`make`

WHERE (`engines`.`status` = 1) AND (`models`.`model` IN ('Camry','DOHC')
OR `engines`.`engine` IN ('Camry','DOHC'))

ORDER BY `makes`.`make`, `models`.`model`, `engines`.`first_year` ASC


RAW Query I get when i search for "DOHC" (shows no results)

Code:
SELECT `engines`.*, `models`.`model` as model_name, `makes`.`make` as make_name
FROM (`engines`)
JOIN `models` ON `models`.`id` = `engines`.`model`
JOIN `makes` ON `makes`.`id` = `engines`.`make`

WHERE (`engines`.`status` = 1) AND (`models`.`model` IN ('DOHC')
OR `engines`.`engine` IN ('DOHC'))

ORDER BY `makes`.`make`, `models`.`model`, `engines`.`first_year` ASC


This doesn't make sense... why is it ignoring the query of the second column?


Messages In This Thread
Help needed with search query - by El Forum - 05-02-2012, 01:41 PM
Help needed with search query - by El Forum - 05-02-2012, 02:41 PM
Help needed with search query - by El Forum - 05-02-2012, 03:43 PM
Help needed with search query - by El Forum - 05-02-2012, 04:16 PM
Help needed with search query - by El Forum - 05-02-2012, 06:02 PM
Help needed with search query - by El Forum - 05-02-2012, 06:18 PM
Help needed with search query - by El Forum - 05-02-2012, 06:24 PM
Help needed with search query - by El Forum - 05-02-2012, 06:28 PM
Help needed with search query - by El Forum - 05-02-2012, 07:16 PM
Help needed with search query - by El Forum - 05-03-2012, 10:06 AM
Help needed with search query - by El Forum - 05-03-2012, 09:57 PM
Help needed with search query - by El Forum - 05-04-2012, 09:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB