0

Greetings

i'm sorry for bother you guys with my questions but i'm in the process of learning php and they say if you want to be the best learn from the best :)

what i want to know is how can i copy a column "field" from a Table lets say A then place this filed at another Table thats B after the copy process is done the filed well be deleted automatically from table A

hope you can help me with this :)

i don't know anything about copying process so i can't post the code i'm working on , i'll put my connection code maybe it will save some of your time....

<?php 

$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "el";


@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect"); 
@mysql_select_db("$db_name") or die ("No database found");
echo"you are connected to the DB";

?>

Edited by Fresco Vivir: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by lyrico
0

You can refer to this idea.
Lets say you have name, address and id to your table both table a and b.

<?php

 $query = mysql_query("SELECT * FROM table_a");
 while($result = mysql_fetch_array($query))
 {
   $name = $result['name'];
   $address = $result['address'];
   $id = $result['id'];

   mysql_query("INSERT INTO table_b (name,address,id) values('$name','$address','$id')");
   mysql_query("DELETE FROM table_a where id='".$id."'");
 }
 
?>

once the loop finished, all the data on table_a will transfer to table_b.

Edited by lyrico: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.