Welcome Guest, Not a member yet? Register   Sign In
CI, DB and ticks
#1

[eluser]Richard Testani[/eluser]
Why does the following:
Code:
$this->db->select('beers.name AS beer, beers.brewid, beers.tagid, beers.stub AS bstub, tags.id, tags.tag, tags.stub AS tstub, breweries.name');
$this->db->from('beers, tags, breweries');
$this->db->where('beers.tagid', 'tags.id');

result in:

Code:
SELECT `beers`.`name` AS beer, `beers`.`brewid`, `beers`.`tagid`, `beers`.`stub` AS bstub, `tags`.`id`, `tags`.`tag`, `tags`.`stub` AS tstub, `breweries`.`name` FROM (`beers`, `tags`, `breweries`) WHERE `beers`.`tagid` = 'tags.id'

Notice the final equation - beers.tagid = tags.id. CI wraps tags.id is wrapped together and with single quote marks and not ticks like the rest. It's breaking my query result.

How can I troubleshoot this?
Thanks
Rich
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

Code:
$this->db->where('beers.tagid = tags.id');
#3

[eluser]Richard Testani[/eluser]
Strangest thing.
I'm not sure why the inconstancies, but after changing the queries, a new error is generated. Now CI is quoting the equation as if it were a table column.

Code:
$this->db->select('beers.name AS beer, beers.brewid, beers.tagid, beers.stub AS bstub, tags.id, tags.tag, tags.stub AS tstub, breweries.name');
$this->db->from('beers, tags, breweries');
$this->db->where('beers.tagid = tags.id');
$this->db->where('tags.stub', $tagName);
$this->db->where('beers.brewid=breweries.id');


Code:
Unknown column 'beers.brewid=breweries.id' in 'where clause'

SELECT `beers`.`name` AS beer, `beers`.`brewid`, `beers`.`tagid`, `beers`.`stub` AS bstub, `tags`.`id`, `tags`.`tag`, `tags`.`stub` AS tstub, `breweries`.`name` FROM (`beers`, `tags`, `breweries`) WHERE `beers`.`tagid` = tags.id AND `tags`.`stub` = 'english_ale' AND `beers`.`brewid=breweries`.`id`

seems like anytime I use tablename.id it gets tripped up.

Any thoughts?
Thanks
Rich
#4

[eluser]TheFuzzy0ne[/eluser]
You need to have the spaces either side of the "=":

Code:
$this->db->where('beers.tagid = tags.id');
#5

[eluser]Richard Testani[/eluser]
YES!
Thats what I needed to know.

Thank you LOL!
Rich




Theme © iAndrew 2016 - Forum software by © MyBB