I want to delete from those lines 'table1' where (user_id = 5) but I should check whether those posts (Title = Title 1 in Table 2). I use Codeigniter and I am getting this error when trying to delete me: 'It is not allowed to be deleted, unless they are "where" or "like" section.' Could you please help me check that is wrong in my code. >
Table 1:
Table 2:
Delete public function ($ title, $ user_id) {$ this- & gt; Db- & gt; Select ('table1. *'); $ This- & gt; Db- & gt; ('Table1', 'table2'); $ This- & gt; Db- & gt; Where ('table1.user_id', $ user_id); $ This- & gt; Db- & gt; Where ('table2.title', $ title); $ This- & gt; Db- & gt; ('Table2' 'table1.post_id = table2.post_id'); $ Query = $ this- & gt; Db- & gt; get receive (); If ($ query & amp; query; & gt; num_rows ()> 0) {$ this- & gt; Db- & gt; Delete ('Table 1. *'); $ This- & gt; Db- & gt; ('Table1', 'table2'); $ This- & gt; Db- & gt; Where ('table1.user_id', $ user_id); $ This- & gt; Db- & gt; Where ('table2.title', $ title); $ This- & gt; Db- & gt; ('Table2' 'table1.post_id = table2.post_id'); Back true; } Other {return false; }}
Use subqueries.
Create an example
where the clause is $ -> Db- & gt; Select ('id'); $ This- & gt; Db- & gt; ('Table2'); $ This- & gt; Db- & gt; Where ('table2.title', $ title); $ Where_clause = $ this- & gt; DB- & gt; Get_compiled_select (); # The main query is $ this-> Db- & gt; Where ('table1.user_id', $ user_id); $ This- & gt; Db- & gt; Where ("` id` is not ($ where_clause) ", NULL, FALSE); $ This- & gt; Db- & gt; Delete ('table1');
Comments
Post a Comment