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?
 
zskull87Connect With a Mentor Author 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.