This question already has answers here:
Increment value in MySQL update query
(10 answers)
Closed 6 years ago.
someone can tell me how to update the value from 0 to 1, 52 to 53 (value++) using php script?
i want to search it on go*gle but i dunno the keyword to find it
If you want to update one column, for example 5_sagnat_baik - just run the query:
UPDATE `question` SET `5_sagnat_baik` = `5_sagnat_baik` + 1
You may update your auto-increment column (known as 'id') using a "update" sql in your php script using something like:
'UPDATE table_name SET id=(id + 1), [column2]=[value2], ...'
OR with PHP computed values (here $current_value):
'UPDATE table_name SET id=' . $current_value + 1 ', [column2]=[value2], ...'
The SQL update request is explained here: http://www.w3schools.com/SQl/sql_update.asp (or here: https://mariadb.com/kb/en/mariadb/update/#syntax)
"UPDATE table_name
SET column_name = column_name+ 1
WHERE condition";
Hope this help
Related
This question already has answers here:
SELECT COUNT(*) AS count - How to use this count
(5 answers)
Closed 1 year ago.
What does this code do? Image to show code
$q57 = mysqli_query($Link, 'select count(*) Registos from t57 where c18="1"') ;
$t57 = mysqli_fetch_array($q57) ;
if($t57['Registos'] == 0) {
what i don't understand is that variable "Registos" in front of the count. Is it doing what there?
That is simply an alias, to help you access the result of count(*).
Otherwise that would become the column name in the result set - remove Registos from the query, and then do a var_dump($t57);, you’ll see what I mean.
The as keyword between the two is optional; select count(*) as Registos would be the “long” way of writing this.
https://www.mysqltutorial.org/mysql-alias/
This question already has answers here:
getting the value of the single field output using the codeigniter active record
(5 answers)
Closed 2 years ago.
hi want to get only one column from one result from my database. So i do it in this way
$this->db->select('myclolumn')->where('id',$id);
$query = $this->db->get('mytable');
$temp=$query->row_array();
$finalresult=$temp['mycolumn'];
Maybe there is a easier or faster way to do the same?
so based on DanishAli's comment
$this->db->select('myclolumn')->where('id',$id);
$query = $this->db->get('mytable');
$finalresult=$query->row()->mycloumn;
You can do it like this:
$finalresult = $this->db->select('myclolumn')
->where('id',$id)
->get('mytable')->row()
->mycolumn;
All in only one command instead of a lot of variables and extra code.
In case you need to provide a default value if the row is null, break the command to:
$row = $this->db->select('myclolumn')
->where('id',$id)
->get('mytable')
->row();
$finalresult = ($row)?$row->mycolumn:'your default value';
This question already has answers here:
Update the value of a field in database by 1 using codeigniter
(3 answers)
Closed 21 days ago.
I have used this query to increment my column with the selected number like
$this->db->where('my Condition');
$this->db->update('my Table',array('name'=>'gautam','count'=>'2'));
Here I want to add 2 to the actual column value of count. But I can't able to do it with update function.And I cont able to do like
$this->db->update('my Table',array('name'=>'gautam','count'=>'count+2'));
because I'm only getting count of "2" and if I add in my query it is adding ' in my query like
enter code here
Can anyone help me to find out the solution for it.
$this->db->set('name', 'gautam');
$this->db->set('count', 'count+2',FALSE);
$this->db->where('my Condition');
$this->db->update('my Table');
$this->db->set() in Codeigniter
You can use Codeigniter set function to set the value of count with the increment .
From the doc
set() will also accept an optional third parameter ($escape), that
will prevent data from being escaped if set to FALSE. To illustrate
the difference, here is set() used both with and without the escape
parameter.
So you can do something like this :
$this->db->where('my Condition');
$this->db->set('count','count+2',FALSE);//SET COUNT WITH COUNT+2
$this->db->set('name','gautam');
$this->db->update('my Table');
Try this :
$this->db->where('my Condition');
$this->db->set(array('count' => 'count+2', 'name' => 'gautam'), FALSE);
$this->db->update('my Table');
This question already has answers here:
Using variables in MySQL UPDATE (PHP/MySQL)
(3 answers)
Closed 7 years ago.
Please help me to write full code in php and sql to update only (point) in table below.
table name : tuser
id_user : 12
name : lisa
username : lisa1990
password : User123
point : 12930
It is very easy...
$con = mysql_connect("servername","username","password");
mysql_select_db("databasename");
$command = "UPDATE tuser SET point='your value' where id=whatever";
//replace 'your value' with the new value and "whatever" with the user id
mysql_query($command);
mysql_close_connection($con);
Next time don't ask so stupid questions here... use Google
This question already has answers here:
Find the parameter names of a stored procedure
(3 answers)
Closed 8 years ago.
When I was using asp, I was able to do the following - now I am using php and sqlsrv - how do I achieve the same in php
Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oConn
oCmd.CommandText = "dbo.spGetItem"
oCmd.CommandType = &H0004 'adCmdStoredProc
oCmd.Parameters.Refresh
For Each prmTemp In oCmd.Parameters
Response.Write( prmTemp.direction & "<br/>" & prmTemp.name)
Next
Set oCmd = Nothing
The simplest way regardless of client language is to just query the metadata / catalog views:
SELECT name, is_output
FROM sys.parameters
WHERE [object_id] = OBJECT_ID('dbo.spGetItem');
select ORDINAL_POSITION, PARAMETER_NAME, DATA_TYPE, PARAMETER_MODE from information_schema.parameters
where specific_name='Proc_Name'