MyBB Community Forums

Full Version: MySQL Variable Assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

Look at this how can do this? Sad

I have two tables in same Database with two different with same name but different table prefixes of course.....

e.g

Quote:myprefix_table
yourprefix_table

these are two tables now they have their variables which are same in data type to each other ....

now what i want is to assign all the variables from "myprefix_table" to "youprefix_table".

Means any change or upgrade to "myprfix_table" should be copied to "yourprfix_table"

So how can i do that in PHP or in SQL?
i dnt know where should it be done ?
so i need you help Sad
you could double your queries..
example
$connection = mysqli_connect('localhost', 'user','pass','dbname');
$sql = "INSERT INTO myprefix_table (username) VALUES ('user1')";
$r = mysqli_query($sql , $connection);
if(mysqli_affected_rows($connection) == 1){
echo "done inseting the data into myprefix_table";
$sql2 = "INSERT INTO yourprefix_table (username) VALUES ('user1')";
$r2 = mysqli_query($sql2, $connection);
if(mysqli_affected_rows($connection) == 1){
echo "done inseting the data into yourprefix_table";
}
else{
echo "can't insert the data to yourprefix_table";
}
}else{
echo "can't insert the data to myprefix_table";
}
thanx pepotiger for you responce

but sorry i cant understand the logic behind.it will just copy users from one table to another ok?
and what about the users value? i mean user1?

and also if i have a very huge Database then will it be a good idea to use this method?
the logic of the code, is to perform the query on table one 1st, if the query ran as well, it'll ran it to the 2nd table..
but it'll not be good with huge databases or to insert huge data
ok i got it now i was confused with two nested conditions in fact .......thanx

oki can you tell me how can assign the data from one table to another.
and its not to copy data from a table to other one what i am asking for.
its just assignment
e.g. assignment of variable1 from a table1 to variable2 in table2 but same database.
means Tables are different but database is same.
and when value of variable1 changes it must also be changed to variable2 as we are assigning it to.
it'll the same thing as I mentioned before, you will have to write you queries two times
one for the 1st table, and the 2nd time for the 2nd table..
oki thanx pepotiger.........

I try this..........