Click to See Complete Forum and Search --> : Table Data mysql


k0r54
11-15-2004, 09:22 AM
Hi,

OK

I have attached a sql dump file and it has two tables in

How do i get the data from
table "one" column "Name" to table "two" column "CN"
table "one" column "City" to table "two" column "Living"
table "one" column "Age" to table "two" column "Age"
table "one" column "ID" to table "two" column "Code"

I need ALL the rows in there, i no there is only two rows and moment but there will be about 10,000 on the live db. This is just a example db and not the real db but the concept will be the same.

Does any1 know how to do this

Thanks
k0r54

k0r54
11-15-2004, 09:43 AM
Sorry here is the attachment

k0r54
11-15-2004, 01:41 PM
Any1 got any ideas????

Im really stuck :(

DJsAC
11-15-2004, 02:37 PM
Wouldn't this work?
$fromcol=$_REQUEST['fromcol'];
$tocol=$_REQUEST['tocol'];
$fromtable=$_REQUEST['fromtable'];
$totable=$_REQUEST['totable'];
$fromdb=$_REQUEST['fromdb'];
$todb=$_REQUEST['todb'];
//From textbox etc.. requiring column names, table names, and database names


$connx = mysql_connect('localhost', 'mysql_user', 'mysql_password');
$db1 = mysql_select_db($fromdb);
//---------//
$result = mysql_query("SELECT ".$fromcol." FROM ".$fromtable." LIMIT 20000"); // limit to prevent script from causing a server timeout.
$fields = mysql_fetch_array($result);
//---------//OR
for ($x=0; $x > $count; $x++) { // you'll have to know howmany rows are in the table..
$result = mysql_query("SELECT ".$fromcol." FROM ".$fromtable." WHERE `id` == '".$x."'");
$fields[$x] = mysql_fetch_row($result);
}
//---------//

$count = count($fields);
$db2 = mysql_select_db($todb);
for ($i=0; $i>=$count; $i++){
$insert = mysql_query("UPDATE ".$totable." SET ".$tocol."='".$fields[$i]."' WHERE `id` == '".$i."'");
}

That's still pretty processor intensive, but should do the trick, or get you partially there... :)

My php still sucks, so you'll probably get 1403 errors while trying to run this, maybe it helps you, probably it doesn't :rolleyes:
Just trying to be of assistance :cool:

k0r54
11-15-2004, 02:39 PM
Many thanks

I will have a look through it now and let u know

:)

Thanks

NogDog
11-15-2004, 02:46 PM
If you are using MySQL 5.0 or later, my guess is that the "right" way to do this in terms of performance would be via MySQL stored procedures (http://dev.mysql.com/doc/mysql/en/Stored_Procedures.html). I personally have not worked with them yet, so pointing you to the link above is about as much help as I can be right now. :(

k0r54
11-16-2004, 05:10 AM
unfortunatly, my hosting service only uses 4.0.18 or sumin :(

Its annoying coz i can do it in access but not mysql :(

Anyone got any idea's i think it may be along the lines off relationships but i dont know how to do that is sql???


Thanks
Adam

k0r54
11-16-2004, 04:23 PM
Ok i have based is on DJsAC

The page is echoing complete but there is no data transfered!

to let you know logos1 table has been truncated so there is no data


<?PHP
$connx = mysql_connect('localhost', 'xx', 'xx');
$db1 = mysql_select_db('apc000001update');

//---------//
$result = mysql_query("SELECT previewpath FROM animations LIMIT 20000"); // limit to prevent script from causing a server timeout.
$fields = mysql_fetch_array($result);

//--------//
$count = count($fields);
$db2 = mysql_select_db('apc000001main');

for ($i=0; $i>=$count; $i++){
$insert = mysql_query("UPDATE logos1 SET Example='".$fields[$i]."' WHERE `id` == '".$i."'");
}

echo "Completed";
?>



Any idea why it is not doing it but i am gettin only completed on the screen

k0r54
11-16-2004, 04:43 PM
I think the reason why its not comin up with an error is because im using update.

I can only update if there are records in there (i think)

I think i need to do a insert.

I can do it in access my making a relation ship between them and using an insert :s

How can i do this in mysql

Any ideas??

Thanks Adam