This question already has answers here:
Update the value of a field in database by 1 using codeigniter
(3 answers)
Update query increment field plus 1 codeigniter function [duplicate]
(1 answer)
Codeigniter update specific value [duplicate]
(2 answers)
Update query increment field plus 1 codeigniter [duplicate]
(3 answers)
How to update a column value with the current column value plus an increment in codeigniter? [duplicate]
(1 answer)
Closed 19 days ago.
I don't know how can I update data in column instead of replacing it. For example now I made simple purchase system and when someone make payment, his old data in the column if it was 5 and the purchase value if its 10, its not going 15 its automatically replacing the old data and adding the new one = 10. Here is the code:
public function updateCoinsRewards($data){
$IGN = $this->session->userdata['Player_Logged']['id'];
$update = $this->db->where('id', $IGN);
$update = $this->db->update($this->CoinsRewards,$data);
return $update?true:false;
}
I tried to make data update instead data replace but didn't make it. Expectation is instead of replacing old data as I said, to add the new one.
This question already has answers here:
PHP PDO retrieves duplicate data
(2 answers)
Closed 1 year ago.
I'm newbie in PHP and when I use PHP to query select, I got 2 values, I realize it may be make slow if have 2 duplicated values.
So I want to ask about it and I also want to get just 1 values from select
thanks for reading my question.
here is picture:
It dipends on what your i guess sql query respondes to your query. However if you want cut down your result in sql you can use LIMIT 1
SELECT ...
FROM ...
WHERE ...
LIMIT 1
This question already has answers here:
When to use VARCHAR and DATE/DATETIME
(5 answers)
Closed 2 years ago.
I have a table that holds few records less than 20. The table (cow_inactive) is just with ID (int) & COW_INACTIVE_DATE (varchar) columns. I am trying to use the DATEDIFF to get all cows that are ready for insemination after 60 Days of being inactive.
SELECT * from cow_inactive where DATEDIFF(CURRENT_DATE, inactive_date)>=60
Result :
Showing rows 0 - 0 (1 total, Query took 0.0022 seconds.)
you need to update field data type COW_INACTIVE_DATE (DATETIME). then run above query
This question already has answers here:
Returning query results in predefined order
(11 answers)
Closed 6 years ago.
I have a IN clause query in which I pass this ID'S (10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29)
My query is,
SELECTpost_jobs.idFROMpost_jobsWHEREidIN(10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29)
It execute correctly and returns result first id likes 1 then 4 then 7 and so on...that is ascending order
My Need is to get first result of id 10 then 19 then 23 as the order of ID that I passed is there any way to get such type of result in output.
Try this
SELECT post_jobs.id FROM post_jobs WHERE id
IN(10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29) ORDER BY
FIELD(id,10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29);
In Codeigniter
$this->db->_protect_identifiers = FALSE;
$this->db->select('id');
$this->db->where_in('id',array(10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29));
$this->db->order_by('FIELD(id, 10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29)');
$this->db->get('post_jobs');
If you are using codeigniter 3 then write or remove the line of protect_identifiers
$this->db->protect_identifiers(False);
Try this one
SELECT post_jobs.id FROM post_jobs WHERE post_jobs.id
IN(10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29) ORDER BY
FIND_IN_SET(post_jobs.id,10,19,23,24,28,33,45,46,1,4,7,8,12,16,18,22,29);
This question already has answers here:
How can I return 10 of the most recent results in sql?
(4 answers)
Closed 9 years ago.
How can i ask a question to a mysql-database (via PDO) to return the 3 latest added rows? The id column is key and auto incremented. That means that highest id means latest added. Don't take into account the fact that rows can have been deleted and such.
Could i somehow use * and LIMIT 3 and start from the bottom some way - or something?
Should be fairly easy but i am kind of stuck.
Order by ID desc limit 3
gives you the three rows with the highest ID. Those are not necessarily the latest three added rows. But they are the latest three added rows still existing in the table.