How can I add the data found from one table to another?
-
Hi I am comparing data between 2 tables looking for what exists in one so i can then enter whatis found into the second table as follows...
mysql_select_db($database_Chartmenu, $Chartmenu);
$query_find_all = "SELECT hankypark.ID FROM hankypark LEFT JOIN tbl_ply_hankypark ON hankypark.ID = tbl_ply_hankypark.Song_ID WHERE (((tbl_ply_hankypark.Song_ID) Is Null))";
$find_all = mysql_query($query_find_all, $Chartmenu) or die(mysql_error());
$row_find_all = mysql_fetch_assoc($find_all);
$totalRows_find_all = mysql_num_rows($find_all);in the hankypark table i know will be entries that do not exist in the tbl_ply_hankypark table hense the Is Null query which gives me an array of the ID field, I now want to add those ID's to the tbl_ply_hankypark table. Question is what do I use to roll through all the ID's found ? My INSERT query looks like this...as said what do use tat the begining is it a... while or do or what?? and how should it be properly laid out please? not having played with arrays I have tried several things from suggestions on the net but none seem to work apart from one that only inserted the first ID and then stopped?
// Insert a row of information into the table "example" mysql_query("INSERT INTO tbl_ply_hankypark (Song_ID) VALUES ('???')")or die(mysql_error());
Thought it best to just bite the bullet and come ask you guys cos your always right lol :) Cheers in advance of any help Regards Ray -
Hi I am comparing data between 2 tables looking for what exists in one so i can then enter whatis found into the second table as follows...
mysql_select_db($database_Chartmenu, $Chartmenu);
$query_find_all = "SELECT hankypark.ID FROM hankypark LEFT JOIN tbl_ply_hankypark ON hankypark.ID = tbl_ply_hankypark.Song_ID WHERE (((tbl_ply_hankypark.Song_ID) Is Null))";
$find_all = mysql_query($query_find_all, $Chartmenu) or die(mysql_error());
$row_find_all = mysql_fetch_assoc($find_all);
$totalRows_find_all = mysql_num_rows($find_all);in the hankypark table i know will be entries that do not exist in the tbl_ply_hankypark table hense the Is Null query which gives me an array of the ID field, I now want to add those ID's to the tbl_ply_hankypark table. Question is what do I use to roll through all the ID's found ? My INSERT query looks like this...as said what do use tat the begining is it a... while or do or what?? and how should it be properly laid out please? not having played with arrays I have tried several things from suggestions on the net but none seem to work apart from one that only inserted the first ID and then stopped?
// Insert a row of information into the table "example" mysql_query("INSERT INTO tbl_ply_hankypark (Song_ID) VALUES ('???')")or die(mysql_error());
Thought it best to just bite the bullet and come ask you guys cos your always right lol :) Cheers in advance of any help Regards RayLook into using an
INSERT/SELECT
statement. -
Hi I am comparing data between 2 tables looking for what exists in one so i can then enter whatis found into the second table as follows...
mysql_select_db($database_Chartmenu, $Chartmenu);
$query_find_all = "SELECT hankypark.ID FROM hankypark LEFT JOIN tbl_ply_hankypark ON hankypark.ID = tbl_ply_hankypark.Song_ID WHERE (((tbl_ply_hankypark.Song_ID) Is Null))";
$find_all = mysql_query($query_find_all, $Chartmenu) or die(mysql_error());
$row_find_all = mysql_fetch_assoc($find_all);
$totalRows_find_all = mysql_num_rows($find_all);in the hankypark table i know will be entries that do not exist in the tbl_ply_hankypark table hense the Is Null query which gives me an array of the ID field, I now want to add those ID's to the tbl_ply_hankypark table. Question is what do I use to roll through all the ID's found ? My INSERT query looks like this...as said what do use tat the begining is it a... while or do or what?? and how should it be properly laid out please? not having played with arrays I have tried several things from suggestions on the net but none seem to work apart from one that only inserted the first ID and then stopped?
// Insert a row of information into the table "example" mysql_query("INSERT INTO tbl_ply_hankypark (Song_ID) VALUES ('???')")or die(mysql_error());
Thought it best to just bite the bullet and come ask you guys cos your always right lol :) Cheers in advance of any help Regards RayOne thing that you can do is combine an insert and a select command together, so you actually get the values inserted that you select from the select query. Your command becomes something like this:
INSERT INTO tbl_ply_hankypark(song_id)
SELECT hankypark.ID FROM hankypark
LEFT JOIN tbl_ply_hankypark ON
hankypark.ID = tbl_ply_hankypark.Song_ID
WHERE (((tbl_ply_hankypark.Song_ID) Is Null))I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
One thing that you can do is combine an insert and a select command together, so you actually get the values inserted that you select from the select query. Your command becomes something like this:
INSERT INTO tbl_ply_hankypark(song_id)
SELECT hankypark.ID FROM hankypark
LEFT JOIN tbl_ply_hankypark ON
hankypark.ID = tbl_ply_hankypark.Song_ID
WHERE (((tbl_ply_hankypark.Song_ID) Is Null))I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
Thnak you for both replies I knew I would get the right directions here Many Thanks for you help Regards Ray
-
Thnak you for both replies I knew I would get the right directions here Many Thanks for you help Regards Ray
You're welcome.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads