Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:38:49+00:00 2026-06-01T10:38:49+00:00

I have a huge table from one mysql db, I want to create a

  • 0

I have a huge table from one mysql db, I want to create a new table in different mysql db and copy 3 columns from the huge one. To do that, I wrote the following code:

$result = mysql_query("SELECT * FROM huge_table", $hugeDB);
    $count = mysql_result($result, 0);
    $iterations=ceil($count/500);    

    for($i=1; $i<=$iterations; $i++)
    {
        $start = ($i-1)*500;
        $query = mysql_query("SELECT col1, col3, col6 FROM huge_table LIMIT $i, 500", $hugeDB);
        $results = array();
        $j = 0;
        while($result = mysql_fetch_array($query)) {
            $result[$j]= '('.$result['col1'].', '.$result['col3'].', '.$result['col6'].')';
            $j++;
        }
        print_r($results);
        $a = mysql_query("INSERT INTO less_huge_table (col1, col3, col6) VALUES ".implode(',', $results), $localDB);
        if(!$a) die(mysql_error()."\n");
    }

But then the output is:

Unknown column 'BTFG' in 'field list'

Where BTFG is the array’s first element’s item:

(2007-01-03, BTFG, 23.0481)

I think I’m making a little mistake but I couldn’t catch.

How should I solve this problem ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:38:51+00:00Added an answer on June 1, 2026 at 10:38 am

    Your array is $result not $resullts. You declared array with $results then assigned values in $result and in insert you are using $results which is blank.

    it should be

      while($result = mysql_fetch_array($query)) {
       $results[$j]= '("'.$result['col1'].'", "'.$result['col3'].'", "'.$result['col6'].'")';
       ....
       }
    

    BTW what is $j++ not used anywhere else.

    EDIT:

    quote char and string values properly:

    ('2007-01-03', 'BTFG', 23.0481)
    

    change here :

     $results[$j]= '("'.$result['col1'].'", "'.$result['col3'].'", "'.$result['col6'].'")';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scripts that retrieves huge data on a table. I want to
Assume that I have one big table with three columns: user_name, user_property, value_of_property. Lat's
I have a huge table and I want simple sorting. It could be so
I have a huge table that is mainly used for backup and administrative purposes.
I have a huge MySQL table which has its rows encoded in UTF-8 twice.
Greeting! I have the following problem. I have a table with huge number of
I have moved my drupal site from one mysql server to another one. Old
I have a huge table with more than one hundred million of rows and
I have an abstract base class that I'm referencing from one of my entities.
I have the following situation: excel-like application, that is accessible from internet. 2 users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.