CodeIgniter update column data instead replace [duplicate] - php

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.

Related

Get data from database using date groups in laravel [duplicate]

This question already has answers here:
Laravel Eloquent get results grouped by days
(17 answers)
Closed 2 years ago.
I am using laravel and I am trying to get data from database grouped by the column "created_at".
The data into created_at column is being stored is in the below format,
2020-07-23 07:03:59
My question is , how can we fetch the data using group for dates only.
For example , All the records should be grouped into one array/object with same dates.
I tried executing the following query,
$transactions= MyTransaction::where('id','=',$user->id)->orderBy('created_at')->get()->groupBy(function($item) {
return $item->created_at->format('Y-m-d');
});
but it does not return what i am expecting, it considers the seconds and hours into the consideration too.
Please guide me solving this query.
$column = \DB::raw("CONCAT(YEAR(`ride_date`),'-',MONTH(`ride_date`),'-',DAY(`ride_date`)) AS `group_column`");
$transactions= MyTransaction::select('*',$column)->where('id','=',$user->id)->orderBy('created_at')->groupBy('group_column')->get();

how to retreive last number in the data [duplicate]

This question already has answers here:
How to retrieve the last 4 characters from a mysql database field?
(4 answers)
Getting last 5 char of string with mysql query
(6 answers)
Query to select strings end with certain character
(6 answers)
Closed 5 years ago.
this is my data in the database and i'm using mysql
database image
How do I retreive number "4" from the data using sql command?
USE reverse and left
set #myfield = 1234;
select left(reverse(#myfield),1) as result;
result
4
demo here
http://rextester.com/LTBE34983

PHP Update Subtract Current Value by 1 [duplicate]

This question already has answers here:
Increase and decrease row value by 1 in MySQL
(5 answers)
Closed 8 years ago.
Hi was wondering if there is a quick way of updating a record in my table but subtracting whatever the current value is by 1 if it's not 0.
I know I can do this by first doing a
SELECT countField FROM myTable Where id="1";
Then get the countField Value and subtract 1 from that value.
Finally:
Update myTable ... etc
Is there a way of doing this without having to do a SELECT and after an UPDATE?
UPDATE table SET countField = countField - 1 WHERE ...

How can i get the inserted seq without using the seq_name? [duplicate]

This question already has answers here:
mysql_insert_id alternative for postgresql
(4 answers)
Closed 8 years ago.
I'm re-developing an open-source program developed with MySql and re-writing an method like:
function lastid(){
return mysql_insert_id($conn);
}
How can i perform this function using postgresql instead?
According to the manual: http://www.postgresql.org/docs/current/static/functions-sequence.html
there is a function lastval() that
Return the value most recently returned by nextval in the current
session. This function is identical to currval, except that instead of
taking the sequence name as an argument it fetches the value of the
last sequence that nextval was used on in the current session. It is
an error to call lastval if nextval has not yet been called in the
current session.

How to return the latest added rows from MySql database. [duplicate]

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.

Categories