calmchess Posted July 15, 2009 Share Posted July 15, 2009 I want to switch id in a database using php so if i choose to switch all the 3 in the database to 2 but then i want all the old 3 to be 2 so what i want is to input 3 and 2 and then on submit all the 3 in the database become 2 and all the 3 become 3. switch places i hope this is clear enough for somebody to write some logic. Quote Link to comment https://forums.phpfreaks.com/topic/165998-switch-id-nums/ Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 http://www.phpfreaks.com/tutorial/php-custom-list-order Quote Link to comment https://forums.phpfreaks.com/topic/165998-switch-id-nums/#findComment-875498 Share on other sites More sharing options...
calmchess Posted July 15, 2009 Author Share Posted July 15, 2009 That is not what i had in mind that only swaps the numbers below or above each row in the database.........I want to exchange numbers anybody got any brilliant code? Quote Link to comment https://forums.phpfreaks.com/topic/165998-switch-id-nums/#findComment-875507 Share on other sites More sharing options...
.josh Posted July 15, 2009 Share Posted July 15, 2009 Did you actually read the tutorial? I already gave you brilliant code. Read the tutorial. The tutorial is about swapping numbers, yes. But how it does it, the db query, is what you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/165998-switch-id-nums/#findComment-875514 Share on other sites More sharing options...
calmchess Posted July 15, 2009 Author Share Posted July 15, 2009 Don't know if anybody can make use of this but here is how i did it. <?php include("../secure_php/admin_database.php"); //exchange 3 with 1 $oldnum =3; $newnum =1; $result0 = mysql_query("SELECT id from page0.page0 where refnum = $oldnum") or die(mysql_error()); while($row0 = mysql_fetch_array( $result0 )){ $ref[]=$row0['id']; echo $ref[0]; echo "test"; } $result3 = mysql_query("Update page0.page0 SET refnum='$oldnum' where refnum='$newnum'") or die(mysql_error()); $result2 = mysql_query("update page0.page0 SET refnum='$newnum' where refnum = '$oldnum' AND id ='$ref[0]' OR id ='$ref[1]'") or die(mysql_error()); $ref=null; ?> Quote Link to comment https://forums.phpfreaks.com/topic/165998-switch-id-nums/#findComment-875548 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.