I have written a code that should copy certain information from a table to another table.
Below are the following codes:
$a = mysql_query("SELECT * FROM table1");
$b = mysql_num_rows($a);
echo '<p>'.$b.'</p>';
for($i=0; $i<$b; $i++)
{
$c = mysql_fetch_array($a);
$d = mysql_fetch_array(mysql_query("SELECT * FROM table2 WHERE user_id = ".$c['id']));
if($d)
{
$e = mysql_query("UPDATE table2 SET user_id = '".$c['id']."',
title = '".$c['profile_title']."',
photo = '".$c['profile_photo']."',
privacy = '".$c['profile_privacy']."',
description = '".$c['profile_description']."',
banner_file = '".$c['banner_file']."',
banner_link = '".$c['banner_link']."',
banner_active = '".$c['banner_active']."' WHERE user_id = ".$c['id']);
echo '(yes) ';
}
else
{
$e = mysql_query("INSERT INTO table2 SET user_id = '".$c['id']."',
title = '".$c['profile_title']."',
photo = '".$c['profile_photo']."',
privacy = '".$c['profile_privacy']."',
description = '".$c['profile_description']."',
banner_file = '".$c['banner_file']."',
banner_link = '".$c['banner_link']."',
banner_active = '".$c['banner_active']."'");
echo '(<b><font color="red">no</font></b>) ';
}
echo $i.'. '.$c['id'].'<br>';
}
echo '<p>'.$i.'</p>';
Now as you can see it copies certain fields from "table1" and put them to "table2".
The problem is that some records are being skipped and I can't seem to figure out why. When i try to echo the records as seen in the code, they output the right amount of data from the query. However when I check the database, they have copied only a certain amount of data. Can you guys help out?
The amount of records are approximately 1,223 but it only copies 1,164 records to table2.


Sign In
Create Account


Back to top









