我的查询在Phpmyadmin上运行正常,但我尝试将此转换为codeigniter查询类型,我不知道如何使用嵌套查询。所以,我想用普通的SQL格式注入这个查询:
<button class="btn-rd-nav" onclick="ShowSearchDiv()" id="btn-search-home">
<i id="search-icon" class="fa-search fa fa-lg3 fa-bg"></i>
</button>
<div id="header-search-form" class="search-form slideInUpbox">
<!----->
<form method="post" action="search-results.asp?action=kword&keyw=&pg=" id="frmsk" name="frmsk" class="home-search">
<div class="input-group">
<input type="text" id="txtsearch" name="txtsearch" placeholder="What are you looking for?">
<button onClick="javascript:gosearch()" class="btn-search" type="submit"><span class="fa-search fa fa-lg"></span></button>
</div>
</form>
</div>
我尝试使用此查询:
select * from conversations c join messages m on m.mconv_num = c.cnum where c.cuser2 = 2 and not exists (select * from messages m2 where m2.mconv_num = m.mconv_num and m2.mtime > m.mtime);
但我有这个错误:
发生数据库错误
$query = 'SELECT * FROM conversations c JOIN messages m ON m.mconv_num = c.cnum WHERE c.cuser2 = 2 AND NOT EXISTS (SELECT * FROM messages m2 WHERE m2.mconv_num = m.mconv_num AND m2.mtime > m.mtime)';
$this->db->query($query);
错误的屏幕截图:https://image.noelshack.com/fichiers/2018/03/5/1516363991-sans-titre.png
因此,如果有人可以帮助我执行我的查询或将此转换为codeigniter格式。谢谢你!
MODEL:
No tables used
SELECT *