0

我真的被这个困住了,我尝试了很多不同的方法,但我无法得到我需要的东西来完成这项工作。拜托,你能告诉我什么是错的,以便我得到这个工作。

在尝试构建一个属性网站时,上传了一个文件(.blm),我需要从这个文件中获取 AGENT_REF 到一个数组中,这样我就可以与数据库进行比较并显示数组差异...... .blm 文件包含信息 AGENT_REF^ADDRESS_1^ADDRESS_2^POSTCODE1^POSTCODE2...

我确信是 AGENT REF 无法正常工作以获得我需要的结果。

请帮我解决这个问题。

<?php 
$rmdata = $rmparser->getPropertyData();

$properties = array();

foreach ($rmdata as $properties) {
$fields = array();
$values = array();
$blmarArray = array();

    foreach ($properties as $field=>$value) {  
        if (!$value) continue;
        $blmarArray = $values[0];
        $agentref = $values[0];
        $fields[] = $field;      
        $values[] = "'".$value."'";     
    } 

    $sql_archeck = mysql_query("SELECT `AGENT_REF` FROM `eprentals`"); 
    $sqlarArray = array(); 
    while($row = mysql_fetch_array($sql_archeck)) {
        $sqlarArray[] = $row['AGENT_REF']; 
    } 

    $combyArrayDiff = array_diff($sqlarArray, $blmarArray);  

    echo '
    <div style="background-color:#ffd7d7;border:#bcbcbc solid 1px;padding:6px;margin-    bottom:6px;">
    <span style="padding:2px;"><p><b>SQL list:</b> ' . implode(', ',   $sqlarArray) . '</p></span>
    <p><b>Uploaded list:</b> ' . implode(', ', $blmarArray) . '</p>
    <p><b>Diff list:</b> ' . implode(', ', $combyArrayDiff ) . '</p>
    </div>
    ';
}

我非常感谢任何帮助,这真的让我很困惑。非常感谢您的参与。

4

2 回答 2

1

我想这就是你想要做的:

/* create 2 empty arrays */
$rm_agentrefs = array();
$db_agentrefs = array();

/* fetch rmdata */
$rmdata = $rmparser->getPropertyData();

/* foreach rmdata */
foreach($rmdata as $current_row)
{
    /* store the Agent Ref in the rm-array */
    $rm_agentrefs[] = $current_row['AGENT_REF'];
}


/* define a database query for fetching agent ref from database */
$db_query = "SELECT `AGENT_REF` FROM `eprentals`";

/* run the database query */
$db_resource = mysql_query($db_query); 

/* fetch each line from the resource */
while($current_row = mysql_fetch_array($db_resource))
{
    /* store each agent ref in the db-array */
    $db_agentrefs[] = $current_row['AGENT_REF']; 
}

/* compare db and rm arrays (missing = db - rm) */
$missing_agentrefs = array_diff($db_agentrefs, $rm_agentrefs);
于 2012-07-20T09:51:18.120 回答
0

这是您的代码现在的剂量:

/* load rmdata */
$rmdata = $rmparser->getPropertyData();

/* make $properties an empty array */
$properties = array();

/* foreach rmdata, replace $properties with the current rmdata */
foreach ($rmdata as $properties)
{
    /* replace 3 variables with empty arrays */
    $fields = array();
    $values = array();
    $blmarArray = array();

    /* for each property */
    foreach ($properties as $field=>$value)
    {
        /* if the propery don't have a value */
        if (!$value)
            /* skip this property */
            continue;

        /* if the propery have a value */
        /* replace $blmarArray and $agentref with the first row in $values, always empty for first property */
        $blmarArray = $values[0];
        $agentref = $values[0];

        /* add current field to the fields array */
        $fields[] = $field;      

        /* add current value (suronded by ') to the values array */
        $values[] = "'".$value."'";     
    }

    /* if there was at least 2 properties with values */
    /* $blmarArray and $agentref have the value of the first of them */

} 
于 2012-07-20T09:00:44.520 回答