Jump to content

switch id nums


calmchess

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/165998-switch-id-nums/
Share on other sites

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;

 

?>

Link to comment
https://forums.phpfreaks.com/topic/165998-switch-id-nums/#findComment-875548
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.