[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

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

0
zskull87
Asked:
zskull87
1 Solution
 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now