Odd Mysql error !?

40 views
Skip to first unread message

Ronny Buelund

unread,
Sep 26, 2024, 1:39:42 PM9/26/24
to Joomla! General Development
I have this code in a plugin:

        // Get id's of articles which are in selected categories and are to old
         $query = $db->getQuery(true)
->select($db->quoteName(array('id', $selecteddatetype, 'catid')))
->from($db->quoteName('#__content'))
->where($db->quoteName($selecteddatetype) . ' >= ' . $db->quote($EndDate))
->where($db->quoteName('catid') . ' IN (' .$categories .')');
            $db->setQuery($query);
        try {
$results = $db->loadAssocList();
        } catch (ExecutionFailureException $e) {
            // This failure isn't critical, don't care too much
            $failed = true;
        }

which works fine, but what I need is this:

        // Get id's of articles which are in selected categories and are to old
         $query = $db->getQuery(true)
->select($db->quoteName(array('id', $selecteddatetype, 'catid')))
->from($db->quoteName('#__content'))
->where($db->quoteName($selecteddatetype) . ' <= ' . $db->quote($EndDate))
->where($db->quoteName('catid') . ' IN (' .$categories .')');
            $db->setQuery($query);
        try {
$results = $db->loadAssocList();
        } catch (ExecutionFailureException $e) {
            // This failure isn't critical, don't care too much
            $failed = true;
        }

which throws an mySQL error ??? I do not get it, the only difference is the greater sign > turned into a lesser sign < 
Why is that not working in joomla db query ??

Grant Hood

unread,
Sep 27, 2024, 3:57:44 AM9/27/24
to Joomla! General Development
Have you checked that the $selecteddatetyp, $categories and $EndDate variables are what you expect them to be? I would try dumping out the resulting query with echo $query->__toString(); and then running it directly on the database (on PhpMyAdmin or command line) to see if it gives you a more meaningful error. If you've not done that before, remember to replace '#__' with your database name prefix or it won't work. Just echoing out the query might highlight an issue with the variables that you hadn't considered as well.

You should be getting something like: SELECT `id`, `created`, `catid` FROM `abcd_content` WHERE (`created` <= '2024-10-01 00:00:00' AND `catid` IN (1,2,3))

Ronny Buelund

unread,
Sep 27, 2024, 4:13:58 AM9/27/24
to Joomla! General Development
As I wrote - the only change is the >= to <= - date is exact the same in db - so that should not the problem.

Grant Hood

unread,
Sep 27, 2024, 4:18:48 AM9/27/24
to Joomla! General Development
I agree, the change to less than shouldn't be an issue, which is why I suggested that you check what the variable values are.

Steven Berkson

unread,
Sep 27, 2024, 4:51:31 AM9/27/24
to joomla-de...@googlegroups.com

If you’re using an IDE, you can view the variables at runtime. I often just set $query->toString = $query->toString(); and then I can see the compiled query in the object, whether it is output to screen or just in the IDE. It may show you that some other value(s) are doing something different from what you expect when you try and look at the inverse relationship.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/joomla-dev-general/57e3c0a7-1c85-4e5f-bd27-8d925cf10cf3n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages