ukscotth Posted November 15, 2009 Share Posted November 15, 2009 Hi, Im trying to copy all data from one table into another while changing a few things on the fly. Basically I have a social networking site and i have a table which stores whos friends with who but I need to store the information in a different way, hence the new table. The problem is with the code im using below it only copies one record for each member e.g if fred has 50 friends its only copying the data for 1 of them. Hope that makes sens and hope someone can help, heres the code : <?php include("include/config.inc.php"); $users = mysql_query("SELECT * FROM joovili_buddies"); while ($got_users = mysql_fetch_array($users)){ $fid = mysql_query("SELECT * FROM joovili_users WHERE username = '".$got_users['buddy_username']."' "); if (mysql_num_rows($fid) == 0) {} else { $fid1 = mysql_fetch_array($fid); } $fid2 = mysql_query("SELECT * FROM joovili_users WHERE username = '".$got_users['buddy_buddy']."' "); if (mysql_num_rows($fid2) == 0) {} else { $fid3 = mysql_fetch_array($fid2); } mysql_query("INSERT INTO userlist (`userid`, `relationid`, `friend`) VALUES ('".$fid1['id']."', '".$fid3['id']."', 'yes')"); } ?> Link to comment https://forums.phpfreaks.com/topic/181635-problem-copying-a-table-plz-help/ Share on other sites More sharing options...
ukscotth Posted November 15, 2009 Author Share Posted November 15, 2009 solved. It was due to having one of the fields set as a primary index. oops. Link to comment https://forums.phpfreaks.com/topic/181635-problem-copying-a-table-plz-help/#findComment-958061 Share on other sites More sharing options...
marklarah Posted November 15, 2009 Share Posted November 15, 2009 Use the "Topic Solved" button. Link to comment https://forums.phpfreaks.com/topic/181635-problem-copying-a-table-plz-help/#findComment-958153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.