You are here: Re: UPDATE and increment by 10 « PHP Programming Language « IT news, forums, messages
Re: UPDATE and increment by 10

Posted by Jerry Stuckle on 10/10/39 11:57

version2 wrote:
> Does any know where a good change order for navigation script or
> tutorial is?
>
> Cause this is what i want to accomplish.
>
> thanks
>

OK, now what you're trying to do makes a lot more sense.

I think the easiest way to do this would be a combination of PHP and
SQL. You can do it all in SQL depending on the release, but this should
work with all releases.

Let's say your table contains, among other things:

id rank
1 10
2 20
3 30
4 40
5 50

And you want to swap 3 and 4.

You can add 15 t0 #3, as you indicated:

id rank
1 10
2 20
3 45
4 40
5 50

Now, to get them in the order:

id rank
1 10
2 20
4 30
3 40
5 50


$rank = 10;
$result1 = mysql_query('SELECT id, rank FROM mytable ORDER BY rank');
while ($data = mysql_fetch_result($result1)) {
$result2 = mysql_query("UPDATE mytable SET rank=$rank WHERE id =
{$data['id']});
$rank += 10;
}


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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