douni9620 2015-09-25 14:09
浏览 67

(PHP)foreach循环没有正确地将我的所有行插入到MYSQL DB中

I have an api which pulls a master list of property listings from a real estate association. When I make the request I get back I .txt file of all the results in my request; this is in a XML structure, I am happy with this because all the results I should get are there. However I also wish to download the listings into a MYSQL DB. This is where I am getting issues. The way the api works that you can only request 100 listings at a time. So you have to build a loop that loops the amount of time of than amount of results you got back divided by 100. Then inside that loop have another loop which loops 100 times(the limit)to pull the listings. So when inside my inner loop which is a foreach loop, I am getting issues, or at least I think its there.

The issue is confusing to me cause when I was doing my testing and i echoed $i and $j within the inner loop and everything counted up fine j went from 0 to 1900 as it should so it does go through each result. Just when I try to use those results for say an echo or DB they dont all seem to be there.

Any help would be much appreciated. I ll try to add just the relevant parts of my scripts rather than my whole scripts.

$TimeBackPull = "-9 months";

error_log("-----GETTING ALL ID's-----");

$DBML = "(LastUpdated=" . date('Y-m-d', strtotime($TimeBackPull)) . ")";

$params = array("Limit" => 1, "Format" => "STANDARD-XML", "Count" => 1);

$results = $RETS->SearchQuery("Property", "Property", $DBML, $params);

$totalAvailable = $results["Count"];

error_log("-----".$totalAvailable." Found-----");

if(empty($totalAvailable) || $totalAvailable == 0)

    print_r($RETS->GetLastServerResponse(), true);  

echo 'total '.$totalAvailable.' <br />';

for($i = 0; $i < ceil($totalAvailable / $RETS_LimitPerQuery); $i++)
{
    $startOffset = $i*$RETS_LimitPerQuery;

    error_log("-----Get IDs For ".$startOffset." to ".($startOffset + $RETS_LimitPerQuery).". Mem: ".round(memory_get_usage()/(1024*1024), 1)."MB-----");

    $params = array("Limit" => $RETS_LimitPerQuery, "Format" => "STANDARD-XML", "Count" => 1, "Offset" => $startOffset);

    $results = $RETS->SearchQuery("Property", "Property", $DBML, $params);      

    foreach($results["Properties"] as $listing)
    {
        echo $listing["AgentDetails"]["@attributes"]["ID"];
    }
}

Another little note is that my ['count'] or in other word the amount of results I get back is what the people i talked to said I should be getting, but the rows inserted or even just echoed never equal up to what It should be

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c