fputs($fp, "Campaign,Daily Budget,Language,Location,Proximity Targets,Ad Schedule,Ad Group,Max CPC,Keyword Type,Keyword,Headline,Description Line 1,Description Line 2,Display URL,Destination URL\r\n"); $cur = 0; $step = 10000; $i = 0; $c = 0; $main_db->executeSQL("SELECT l_geo_city, l_rooms, l_assetType, min(l_d_price) as l_d_price, count(*) as cnt FROM realestate WHERE l_www_id = 16 and l_isActive = 1 and l_d_price > 1500 and l_rooms < 4 and l_deal_type = 0 GROUP BY l_geo_city, l_rooms, l_assetType HAVING cnt > 10 ORDER BY cnt DESC", $resultArry, $rowsAffected); $total = $rowsAffected; foreach ($resultArry as $val) { echo $c . "/" . ++$i . "\r\n"; $ag = new GoogleAdGroup($db); $ag->m_sMainTable = 'realestate'; $ag->gag_l_id = $val['l_id']; $ag->gag_name = "Group " . $c; $ag->save(); $ag->buildAds(array("GoogleAdRealEstateIL"), $val); $ag->buildRealEstateKeywordsIL($val); $ag->saveAds($fp, $campaign->ga_campaign_name); if (!$ag->is_has_ads) { echo "no good ads\r\n"; continue; } foreach ($ag->m_aKeywords as $val) { fputs($fp, "{$campaign->ga_campaign_name},,,,,," . $ag->gag_name . "," . MAX_CPC . "," . DEFAULT_MATCH_TYPE . ",{$val}\r\n"); } $c++; if ($c == 2000) { $c = 0; $campaign = new GoogleCampaign($db); $campaign->ga_campaign_name = CAMPAIGN_NAME_BASE . " " . date("Y-m-d H i"); $campaign->save(); }