Bazilisk Posted July 21, 2021 Posted July 21, 2021 (edited) Have error for MySQL select: $select = \IPS\Db::i()->select( '*', 'news_artcms_news', array('categorynum LIKE ?','%main%'), 'news_artcms_news.num DESC', array( 0, 12 ) ); $results = \IPS\Db::i()->query($select); Quote You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ORDER BY news_artcms_news.num DESC LIMIT 0,12' at line 1 Where is my mistake? I try to change problems code: array('categorynum LIKE ?','%main%') to array('categorynum = ?','main') but error dont fixed.... categorynum is text field Edited July 21, 2021 by Bazilisk
Ryan Ashbrook Posted July 21, 2021 Posted July 21, 2021 Try using the like() method instead. Also, you do not need to pass your query to query() - simply convert $select to an array using the iterator_to_array() function. $select = \IPS\Db::i()->select( '*', 'news_artcms_news', array( \IPS\Db::i()->like( 'categorynum', 'main', TRUE, TRUE ) ), 'news_artcms_news.num DESC', array( 0, 12 ) ); $results = iterator_to_array($select); Bazilisk 1
Bazilisk Posted July 21, 2021 Author Posted July 21, 2021 (edited) Thanks. all Ok now. Is it possible to add "AND" rules in WHERE to make second select option? Edited July 21, 2021 by Bazilisk
Recommended Posts