sekowe Posted July 14, 2007 Share Posted July 14, 2007 I want to be able to make a list of number in a colum that changes when a line is added to the middle of it. I have looked for it but cant find anything about it. I will put an axample to explain myself better. # | | | | | ------------------ 1 | a | a | a | a | 2 | h | h | h | h | 3 | n | n | n | n | 4 | z | z | z | z | Now i want to add a c value between a and h # | | | | | ------------------ 1 | a | a | a | a | 2 | h | h | h | h | <---------- 3 | c | c | c | c | I want it to get number 3 automatically and that the rest of the numbers rols one forward. 3 | n | n | n | n | 4 | z | z | z | z | Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 14, 2007 Share Posted July 14, 2007 is this a database or where are you getting this info? Quote Link to comment Share on other sites More sharing options...
sekowe Posted July 14, 2007 Author Share Posted July 14, 2007 The info comes from a mysql database. Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted July 14, 2007 Share Posted July 14, 2007 so if a form inputs the id and the info like n or c or watever Id = 3 info = C | C | C so far you have 1 | a | a | a | a | 2 | h | h | h | h | 3 | n | n | n | n | 4 | z | z | z | z | ' and you want to change every thing past it to 1 + <?php $id = 3; $query = mysql_query("SELECT * FROM table LIMIT $id-1,18446744073709551615"); while($info = mysql_fetch_array($query)) { $update = mysql_query("UPDATE table SET id = $info[id]+1 WHERE id = $info[id]"); } $insert = mysql_query("INSERT INTO table (id,value) VALUES('$id','C')"); ?> this code is very inpractical becuase if you did have 10,000 database entries it would have to cycle through 9,997 and add 1 to each id. Quote Link to comment Share on other sites More sharing options...
sekowe Posted July 15, 2007 Author Share Posted July 15, 2007 I will try out what you just said. But i dont necesarily need it to be on the database. It could also be at the table directly so that it would be independent of the database. Thats actually what i had in mind. It could be something like: <?php $nc321 = 1; $nc572 = $nc00001 + 1; $nc843 = $nc00002 + 1; $nc443 = $nc00003 + 1; $nc874 = $nc00004 + 1; echo $nc00001; echo $nc00002; echo $nc00003; echo $nc00004; echo $nc00005; ?> And then when i want to add one all i have to do is: <?php $nc321 = 1; $nc572 = $nc321 + 1; $nc843 = $nc572 + 1; <--- add a row $nc111 = $nc843 + 1; $nc443 = $nc843 + 1; (change red to $nc111) $nc874 = $nc443 + 1; echo $nc321; echo $nc572; <-----add row echo $nc111; echo $nc443; echo $nc874; ?> But i was wondering if there is a code for wich i wouldnt have to write it 1000 times if i have 500 rows. Kind of the effect two tables would have if floating next to each as long as every row has the same size. You add one number to the end of the number table and add a row to the middle of the data table. The code i put is very simple, its because i am just starting. Actualy the first time for me. Quote Link to comment Share on other sites More sharing options...
sekowe Posted July 18, 2007 Author Share Posted July 18, 2007 so if a form inputs the id and the info like n or c or watever Id = 3 info = C | C | C so far you have 1 | a | a | a | a | 2 | h | h | h | h | 3 | n | n | n | n | 4 | z | z | z | z | ' and you want to change every thing past it to 1 + <?php $id = 3; $query = mysql_query("SELECT * FROM table LIMIT $id-1,18446744073709551615"); while($info = mysql_fetch_array($query)) { $update = mysql_query("UPDATE table SET id = $info[id]+1 WHERE id = $info[id]"); } $insert = mysql_query("INSERT INTO table (id,value) VALUES('$id','C')"); ?> this code is very inpractical becuase if you did have 10,000 database entries it would have to cycle through 9,997 and add 1 to each id. This works but its not really what i had in mind. Thanks anyway. Will keep looking for a better option. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.