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

  • Home
  • SEARCH
  • 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 6094167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:38:45+00:00 2026-05-23T12:38:45+00:00

I hope someone can help. The following piece of php code (see below) is

  • 0

I hope someone can help.

The following piece of php code (see below) is used to pull all the available products from a database and save them locally to a xml file (somefile.xml) so that google can come every day and and pick it to keep our merchant account or also known as google base up to date.

Since my inventory has grown to over 200K products, google will not accept the file any more as it is over 20 meg big and has asked me to split it in smaller files.

So I’m looking for a way to make this query save the products in multiple files, let’s say create a brand new file every 10000 rows (or products) with a new file name in sequence (e.g somefile1.xml, somefile2.xml, etc etc…) while maintaining the xml file header and footer in each file.

$fp = fopen(BASE_PATH.'/somefile.xml','w');

    $db->query("
        SELECT ".DB_PREFIX."products.*, 
        WHERE ".DB_PREFIX."products.available='Yes'
        ORDER BY title
        ");

///header
$xmlPacket =
'<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>'.$settings["GlobalSiteName"].'</title>
<link>'.$settings["GlobalHttpUrl"].'</link>

    while($db->moveNext()){

            $product_url = $db->col["product_url"];
            $name = $db->col["title"];
            $condition = $db->col["condition"];

///products         
$xmlPacket .=
"\n<item>
  <title>".st_normalize($name)." (SKU ".st_normalize($pid).")</title>
  <link>".st_normalize($product_url)."</link>
  <g:condition>".st_normalize($condition)."</g:condition>
</item>\n";

        }

///footer   
$xmlPacket .=
'</channel>
</rss>';

fwrite($fp,$xmlPacket);
fclose($fp);

Please if someone has any idea how to accomplish this, please share any thoughts.

Thanks and have a nice day!

  • 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-05-23T12:38:45+00:00Added an answer on May 23, 2026 at 12:38 pm

    This should do what you need:

    define(BASE_NAME, 'somefile');
    define(MAX_ROWS, 10000);
    
    $db->query("SELECT ".DB_PREFIX."products.*, WHERE ".DB_PREFIX."products.available='Yes' ORDER BY title");
    
    $header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rss version=\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\">\n<channel>\n<title>".$settings["GlobalSiteName"]."</title>\n<link>".$settings["GlobalHttpUrl"]."</link>";
    $footer = "</channel>\n</rss>";
    
    $n = 0;
    $i = 0;
    while($db->moveNext()){
        if (!($i % MAX_ROWS)) {
            if ($n) {
                fwrite($fp, $footer);
                fclose($fp);
            }
            $i = 0;
            $n++;
            $fp = fopen(BASE_PATH.'/'.BASE_NAME.$n.'.xml', 'w');
            fwrite($fp, $header);
        }
    
        $product_url = $db->col["product_url"];
        $name = $db->col["title"];
        $condition = $db->col["condition"];
    
        fwrite($fp, "\n<item>\n<title>".st_normalize($name)." (SKU ".st_normalize($pid).")</title>\n<link>".st_normalize($product_url)."</link>\n<g:condition>".st_normalize($condition)."</g:condition>\n</item>\n");
        $i++;
    }
    
    fwrite($fp, $footer);
    fclose($fp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope someone can help me with the following... I have this code below
I hope someone can help me with the following: I need to know if
I hope someone can help me... Josh Smith did a great article on WPF
I hope someone can help here, we're having an incredibly annoying time with Visual
I hope someone can help me find an answer. I'm working with a legacy
Hi and good evening, hope someone can help. I am trying to get some
I need to do a non greedy match and hope someone can help me.
I'm new to iPhone development and have a question I hope someone can help
I'm almost losing it, i really hope someone can help me out! I'm using
This is really bugging me, so I hope someone can help me a bit

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.