where-clause

codeigniter ActiveRecord where statement issue

好久不见. 提交于 2020-03-06 09:15:37
问题 is have this statement and i want to make it by the Active Records way in codeigniter DELETE FROM TABLE (col1 = value AND col2 = value2 ) OR (col1 = value2 AND col2 = value ); 回答1: CodeIgniter Active Record is impractical for mixing AND's and OR's within a query. You will likely need to construct some of the query manually, e.g. something along the lines of: $this->db->where("col1 = $value AND col2 = $value2"); $this->db->or_where("col1 = $value2 AND col2 = $value"); Alternately, in your

How to use variables in WHERE clause for a SQL SELECT query

时光毁灭记忆、已成空白 提交于 2020-02-25 05:27:08
问题 My SQL SELECT query has 3 variables set by a HTML form, however these variables can be null: $suburb = (isset($_POST['suburb'])) ? $_POST['suburb'] : ''; $postcode = (isset($_POST['postcode'])) ? $_POST['postcode'] : ''; $state = (isset($_POST['state'])) ? $_POST['state'] : ''; When all 3 variables are entered in the form the SELECT query processes fine (due to the AND's in the WHERE clause). But when one or more variables are blank, the SELECT query errors as it is looking for a NULL value

How to use variables in WHERE clause for a SQL SELECT query

戏子无情 提交于 2020-02-25 05:26:22
问题 My SQL SELECT query has 3 variables set by a HTML form, however these variables can be null: $suburb = (isset($_POST['suburb'])) ? $_POST['suburb'] : ''; $postcode = (isset($_POST['postcode'])) ? $_POST['postcode'] : ''; $state = (isset($_POST['state'])) ? $_POST['state'] : ''; When all 3 variables are entered in the form the SELECT query processes fine (due to the AND's in the WHERE clause). But when one or more variables are blank, the SELECT query errors as it is looking for a NULL value

How to use variables in WHERE clause for a SQL SELECT query

大城市里の小女人 提交于 2020-02-25 05:26:08
问题 My SQL SELECT query has 3 variables set by a HTML form, however these variables can be null: $suburb = (isset($_POST['suburb'])) ? $_POST['suburb'] : ''; $postcode = (isset($_POST['postcode'])) ? $_POST['postcode'] : ''; $state = (isset($_POST['state'])) ? $_POST['state'] : ''; When all 3 variables are entered in the form the SELECT query processes fine (due to the AND's in the WHERE clause). But when one or more variables are blank, the SELECT query errors as it is looking for a NULL value

SQL: Can I negate a condition in a where clause?

﹥>﹥吖頭↗ 提交于 2020-02-14 05:45:39
问题 I want to check if a boolean is true, then decide in the WHERE clause what condition to use. Say the boolean variable is @checkbool: SELECT * FROM TableA A WHERE --if @checkbool is true, run this A.Id = 123 --if @checkbool is false, run this A.Id <> 123 Is there a way to negate a condition? Like in C++ you can do if !(condition). If not, what is the best way to solve this problem? Thank you! 回答1: SQL's equivalent of ! in C is NOT . However, in your case you want something else: you need to

SQL: Can I negate a condition in a where clause?

拟墨画扇 提交于 2020-02-14 05:43:26
问题 I want to check if a boolean is true, then decide in the WHERE clause what condition to use. Say the boolean variable is @checkbool: SELECT * FROM TableA A WHERE --if @checkbool is true, run this A.Id = 123 --if @checkbool is false, run this A.Id <> 123 Is there a way to negate a condition? Like in C++ you can do if !(condition). If not, what is the best way to solve this problem? Thank you! 回答1: SQL's equivalent of ! in C is NOT . However, in your case you want something else: you need to

Solve query sql with rails

微笑、不失礼 提交于 2020-01-26 04:39:04
问题 I need that when I create a Historic do it: Table historic id authorization_origin_id 1 2 2 3 How you see in image bellow This is my new.html.erb <%= simple_form_for(@refinancing) do |f| %> <div class="form-inputs"> <%= f.hidden_field :employee_id, value: @employee.first.id %> <%= f.input :contract_number %> </div> <h3>Reserved value</h3> <table class="table table-condensed table-bordered table-striped"> <thead> <th>Authorization id</th> <th>Contract number</th> </thead> <% @authorizations

MySQL SELECT values with more than three words

元气小坏坏 提交于 2020-01-25 11:39:25
问题 I currently have the following code select * FROM list WHERE name LIKE '___' ORDER BY name; I am trying to get it so that it only shows names with three or more words. It only displays names with three characters I cannot seem to work out the correct syntax for this. Any help is appreciated Thankyou 回答1: If you assume that there are no double spaces, you can do: WHERE name like '% % %' To get names with three or more words. If you can have double spaces (or other punctuation), then you are

Filtering a datatable row using a where clause

我与影子孤独终老i 提交于 2020-01-24 09:10:22
问题 I have a DataTable that I am pulling from a DataSet. From the DataTable, I want to use the Where clause to return a particular row. I looked at "How can I select a row from a datatable using two variable values?" but I get an error "Cannot implicitly convert type 'System.Data.DataRow[]' to 'System.Data.DataRow'" I searched google, but could not find a solution. My code is: mySqlDataAdapter.Fill(myDataSet); DataTable dtTable = myDataSet.Tables[0]; DataRow dr = dtTable.Select("VendorID = " +

Filtering a datatable row using a where clause

荒凉一梦 提交于 2020-01-24 09:10:06
问题 I have a DataTable that I am pulling from a DataSet. From the DataTable, I want to use the Where clause to return a particular row. I looked at "How can I select a row from a datatable using two variable values?" but I get an error "Cannot implicitly convert type 'System.Data.DataRow[]' to 'System.Data.DataRow'" I searched google, but could not find a solution. My code is: mySqlDataAdapter.Fill(myDataSet); DataTable dtTable = myDataSet.Tables[0]; DataRow dr = dtTable.Select("VendorID = " +