문제

I'm really getting stuck with this, I've tried so many different ways and I am unable to get what I need in order to make this work. Please, can you show me what's wrong in order for me to get this working.

In trying to build a property website a file (.blm) is uploaded, I am in need of getting the AGENT_REF from this file into an array so I can compare against the database and show the array difference... The .blm file contains information AGENT_REF^ADDRESS_1^ADDRESS_2^POSTCODE1^POSTCODE2...

I am convinced that it's the AGENT REF that's not working correctly in order to get the results I need.

Please help me solve this.

<?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>
    ';
}

I Greatly appreciate any assistance from this, it's really got me baffled. Thank you so much for your time.

도움이 되었습니까?

해결책

I guess this is what you want to do:

/* 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);

다른 팁

Here is what your code dose now:

/* 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 */

} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top