Have a Auto-Update to all numbers

Im trying to change the numbers it kinda works in sql part when i look at it it skips number 2 but changes number num to 4 i dont understand why
$query = "UPDATE `tos` SET `num` = '2'";
$result = mysql_query($query);
 
$my = -1;
$y = -1;
$i = 1;
$query4 = "SELECT `id` FROM `tos`";
$result4 = mysql_query($query4);
while($row4 = mysql_fetch_array($result4))
{
	$q = $i;
	if($row["id"] == "2" OR $q == "4")
	{
	$y = "UPDATE `tos` SET `num` = '4' WHERE `id` = '2'";
	$my = mysql_query($y);
	print'<br>'.$row4["id"].''.$q.'<br>';
	}
	else
	{
	$y = "UPDATE `tos` SET `num` = '".$q."' WHERE `id` = '".$row4["id"]."'";
	$my = mysql_query($y);
	print''.$row4["id"].'/'.$q.'';
	}
	$i++;
	$my++;
	$y++;
}

Open in new window

zskull87Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zskull87Author Commented:
Never mind heres the solution I came up with it works great if u want to manually organize your tos. For example if you have it ordering by name or id and u have no control where each one will be at now you do with this code it will set the num how you want it and all of your coding is in your control or the user.
$query = "UPDATE `tos` SET `num` = '2'";
$result = mysql_query($query);
 
$my = -1;
$y = -1;
$i = 1;
$query = "UPDATE `tos` SET `num` = '3' WHERE `id` = '2'";
$result = mysql_query($query);
$query4 = "SELECT `id`, `num` FROM `tos`";
$result4 = mysql_query($query4);
while($row4 = mysql_fetch_array($result4))
{
	
	
	if($row4["id"] == "2")
	{
	$i = $i-1;
		print'<br>'.$row4["id"].'/'.$i.'<br>';
	$i++;
	}
	elseif($i == "3")
	{
	$my3 = $i+1;
	$i = $i+1;
	$y = "UPDATE `tos` SET `num` = '".$my3."' WHERE `id` = '".$row4["id"]."'";
	$my = mysql_query($y);
		print'<br>'.$row4["id"].'/'.$i.'<br>';
	$i++;
	}
	else
	{
	$y = "UPDATE `tos` SET `num` = '".$i."' WHERE `id` = '".$row4["id"]."'";
	$my = mysql_query($y);
	print''.$row4["id"].'/'.$my.'';
	$i++;
	}
	
	$my++;
	$y++;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.