Another MySQL question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Another MySQL question (/showthread.php?tid=5019) |
Another MySQL question - El Forum - 12-31-2007 [eluser]codex[/eluser] Imagine a 'project'-table with, besides the projectdata itself, 3 fields: - project_creator_id = the id of the person who created the project - project_client_id = the id of the person for whom the project is done - project_contractor_id = the id of the person who will realise the project The project creator can either be the client or the contractor, so at least 2 id's will be the same. I want to show the projects that were NOT created by the user id (uid) in the current session (me), but where I am either the client or contractor. So in short: how would you say 'give me the rows where either uid is project_client_id or project_contractor_id, but NOT where uid is project_creator_id' This doesn't work: Code: function get_co_projects() It's basically the OR that screws it up. Another MySQL question - El Forum - 12-31-2007 [eluser]Skulls[/eluser] Code: $try_this_sql=" SELECT * from projects WHERE ((project_client_id=$this->session->userdata('uid')) OR (project_contractor_id=$this->session->userdata('uid') )) use the brackets to group conditions .. where (color=red or color=green) and (color!=black) Another MySQL question - El Forum - 12-31-2007 [eluser]codex[/eluser] [quote author="Skulls" date="1199140084"] Code: $try_this_sql=" SELECT * from projects WHERE ((project_client_id=$this->session->userdata('uid')) OR (project_contractor_id=$this->session->userdata('uid') )) use the brackets to group conditions .. where (color=red or color=green) and (color!=black)[/quote] Yaay! Didn't know about/think of bracketing, but it makes perfect sense. Thanks! |