Talk

Selecting data using JDatabase: Difference between revisions

From Joomla! Documentation

How to perform 2 or more queries consecutively?
 
m added paragraph, marked EDIT
Line 4: Line 4:


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);"
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).
--[[User:Marvin Martiano|Marvin Martiano]] ([[User talk:Marvin Martiano|talk]]) 15:12, 25 November 2014 (CST)
--[[User:Marvin Martiano|Marvin Martiano]] ([[User talk:Marvin Martiano|talk]]) 15:12, 25 November 2014 (CST)

Revision as of 22:16, 25 November 2014

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)