473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is there any special way for variable++?

Say I have a table in a MySQL server
ID USERNAME COUNT
0 JOHN 2
1 JANE 3
2 HOMER 3
3 MOE 2

If I want to increase Homer's count by 1,
The plain way would be;
1)$TEMP=SELECT COUNT WHERE ID=2
2)$TEMP++
2)UPDATE .. SET COUNT=$temp...
I guess if there is any special way to increase the int value by one?
For increasing 1 is so commonly used (that's why c,c++,java,C# has the
operator ++).

Oct 22 '05 #1
2 3540
ty*******@gmail.com wrote:
Say I have a table in a MySQL server
ID USERNAME COUNT
0 JOHN 2
1 JANE 3
2 HOMER 3
3 MOE 2
Generally, it's a bad idea to give a column a name that is also a sql
preserved word (count).
If I want to increase Homer's count by 1,
The plain way would be;
1)$TEMP=SELECT COUNT WHERE ID=2
2)$TEMP++
2)UPDATE .. SET COUNT=$temp...
No, you would let the database do the work:

UPDATE Tablename SET count=count+1 WHERE id=2

May need `` around count, because of problem mentioned above. See
http://php.net/mysql-query and
http://dev.mysql.com/doc/refman/4.1/en/update.html
I guess if there is any special way to increase the int value by one?
For increasing 1 is so commonly used (that's why c,c++,java,C# has the
operator ++).


Yes, that operator also exists in PHP:
http://php.net/manual/en/language.op....increment.php

--
E. Dronkert
Oct 22 '05 #2
you can do this in the mysql itself depending on what server version
you are using. try update .. set count=count+1 where id=2 and
username="homer";

ty*******@gmail.com wrote:
Say I have a table in a MySQL server
ID USERNAME COUNT
0 JOHN 2
1 JANE 3
2 HOMER 3
3 MOE 2

If I want to increase Homer's count by 1,
The plain way would be;
1)$TEMP=SELECT COUNT WHERE ID=2
2)$TEMP++
2)UPDATE .. SET COUNT=$temp...
I guess if there is any special way to increase the int value by one?
For increasing 1 is so commonly used (that's why c,c++,java,C# has the
operator ++).


Oct 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bernhard Georg Enders | last post by:
I'm using the php 'file' command to read the contents of an ASCII text file to a variable. The original text file contains some accented and special characters. The problem arises when I echo this...
14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
2
by: Jim Schueler | last post by:
Here is some sample code that uses inherited class methods: sub parseHTML::docomment { my $comment = shift ; print $comment, "\n" ; } sub parseASP::AUTOLOAD { use vars qw( $AUTOLOAD ) ;
1
by: Vannela | last post by:
In my unmamaged code varaibles declaration can use special characters like - Dash _ Underscore (C# allows except this) $ Dollar sign # Number sign % Percent sign but C# will...
4
by: dutch disCo | last post by:
Hi, I'm trying to use GET method to pass variables through my script files. Unfortunately, when a special char (&, ?, +) is being posted the variable gets trimmed in a very strange way. I'm...
8
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have...
0
by: news.online.de | last post by:
Hello everybody, probably it's a FAQ but I didn't find anything so far concerning my problem, so I am asking here :-) I am facing the following problem: - I have developed a webservice client...
0
by: smith2 | last post by:
Hi, I have a string which has special chars coming in an input file. I want to set it in a wstring variable present in table . It is not setting the wstring variable if it has any special...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.