You are here: Re: Is there any special way for variable++? « PHP Programming Language « IT news, forums, messages
Re: Is there any special way for variable++?

Posted by Ewoud Dronkert on 10/22/05 13:58

typingcat@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.operators.increment.php

--
E. Dronkert

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация