Jump to content

Problem copying a table, plz help


ukscotth

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.