I have been pulling my hair out with this query for the last 2 days and have read and re-read the 2 other similar posts with no luck.
Scenario: I am gathering two inputs from a user: Test ID Code and email address they used when submitting the test. The test code is numbers and can have a letter in the beginning, but the testing facility may leave this number out so I add the letter to a variable in the query (reason for "newtidcode" you will see below). They can also provide up to 4 email addresses to the tester when submitting (reason for me testing on 4 email possibilities).
Here is my query:
$query->select($db->quoteName(array('tidcode', 'cdcode','email1', 'email2', 'email3', 'email4', 'status')))
->from($db->quoteName('#__tid_codes'))
->where($db->quoteName('tidcode').' = '.$db->quote($tidcode), 'OR')
->where($db->quoteName('tidcode').' = '.$db->quote($newtidcode), 'AND')
->where('('.$db->quoteName('email1').' = '.$db->quote($email).' OR '.$db->quoteName('email2').' = '.$db->quote($email).' OR '.$db->quoteName('email3').' = '.$db->quote($email).' OR '.$db->quoteName('email4').' = '.$db->quote($email).')');
Here the SQL Statement created:
SELECT `tidcode`,`cdcode`,`email1`,`email2`,`email3`,`email4`,`status` FROM `#__tid_codes` WHERE `tidcode` = '10348' OR `tidcode` = 'F10348' OR (`email1` = '[email protected]' OR `email2` = '[email protected]' OR `email3` = '[email protected]' OR `email4` = '[email protected]')
As you can see the OR before the email should be an AND as specified in the 2nd "where" statement. I was even trying to use conditions arrays like below and still ran into the same thing.
$conditions1 = array(
$db->quoteName('tidcode')." = ".$db->quote($tidcode),
$db->quoteName('tidcode')." = ".$db->quote($newtidcode)
);
$conditions2 = array (
$db->quoteName('email1')." = ".$db->quote($email),
$db->quoteName('email2')." = ".$db->quote($email),
$db->quoteName('email3')." = ".$db->quote($email),
$db->quoteName('email4')." = ".$db->quote($email)
);
This is my first foray in JDatabase querying to this complexity. I have this application working fine in standard HTML and PHP, but trying to port over to Joomla. Any help is highly appreciated.
AND
in your 2ndwhere
clause, but it doesn't appear to be visible in your native SQL statement. It's showingOR
instead. Is this the issue or purposely done?