Selecting data using JDatabase
From Joomla! Documentation
What with multiple, separate queries? Do we have to reset the $query?
I'm a total beginner, and am running into some problems so searching around, and tinkering with Joomla 3.3.x. I find no explanations online, and have not even run into authorative samples so far. Therefore, I think this page needs an example of how to perform two, possibly unrelated, queries in a row.
Basically, I try several examples from the page inside a module displayed inside a Joomla article -- and it gives an error page with a #1066 mysql error near bottom. I repeat a working example: same effect. I insert a second "$query = $db->getQuery(true);" between the copies: hurray, it works! I understand why it works, but I don't know if that's the right approach, and I don't understand why it doesn't work without... So I don't know if I should be able to simply re-use my "$query", whether I should start by reserving multiple queries (something like "$query1, $query2, ... = $db->getQuery(true);"
EDIT (1h later): Using JDEBUG as suggested elsewhere (How_to_debug_your_code) it is clear where the #1066 comes from, but not yet what is best practice (several $query_i variables or one, and if one how to reset). --Marvin Martiano (talk) 15:12, 25 November 2014 (CST)
EDIT (years later): I don't have the above problem, I don't remember what was the problem even. BUT! It seems to me there's a problem with the line
where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'custom.%\''))
which gave me empty results [and commenting out gave me all results, using var_dump($results)]: Namely, the quotes around the 'custom'; correct results were gotten from
where($db->quoteName('profile_key') . ' LIKE '. $db->quote('custom.%'))
I can't say if I'm doing something wrong, or the instructions are wrong, so I'm not editing the page.--Marvin Martiano (talk) 10:38, 3 October 2017 (CDT)