I am creating a simple PHP webpage with MySQL database. The MYSQL database have the following contents: (illustration on left) I just want to know a possible way of doing some Data Manipulation to achieve the results on the right portion below.
(initial value) (final result)
ID | MINUS '1'(to "next" ID's) ID | ID |
1 | 0 1 | ------------> 1 |
2 | 1 --> (will minus '1' to ID 3 2 | ------------> 2 |
3 | 0 up to the last) 3-1 = 2 | ------------> 2 |
4 | 0 4-1 = 3 | ------------> 3 |
5 | 1 --> (minus '1' AGAIN to ID 6 5-1 = 4 | ------------> 4 |
6 | 0 up to the last) 6-1 = 5 -1 ---> 4 |
7 | 0 7-1 = 6 -1 ---> 5 |
It is just COUNTING the number of minus and then subtracting it to ALL the ID that follows it. ID 2 has tells the next ID, which is 3 to subtract 1 to itself up to the last ID, (3-1 , 4-1, 5-1, 6-1, 7-1 ) but another instance came. ID 5 tells ID 6 to subtract itself again up to the last, so MINUS 2 from ID 6 up to the last ID. from just 6-1, 7-1 ---> 6-2, 7-2.
I know it sounds very easy for you, but I'm just a newbie and find this thing hard. Sorry for the headache. Hope someone helps, Thanks!
my DML is like (just for illustration, this should be in php, I will convert it, just help me in the LOGIC)
for($x=0;$x<num_rows;$x++)
{
if(MINUS = 1){
query(UPDATE table_name SET ID=ID-1 WHERE ID = $x);}
}
Something like that, i am still a newbie in decision making loops. I will be grateful if you could fix my loop. I am new to this community, I beg for your understanding.