0

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.

5
  • what do you get when you var_dump($row) ? Commented Jul 20, 2012 at 8:59
  • You should restudy your code before asking. Look at the second foreach instruction: foreach ($properties as $field=>$value) { if (!$value) continue; $blmar = $values[0]; } Why would you retrieve keys in $field and then not use them? $blmar was created as an array, but in that loop you keep on redefining its content. Maybe you wanted to do something like $blmar[$field] = $value Commented Jul 20, 2012 at 8:59
  • 1
    What does $rmdata look like, mind adding a var_dump($rmdata) or var_export($rmdata) of that value Commented Jul 20, 2012 at 8:59
  • I've removed some lines as thought it'd be too much :) Commented Jul 20, 2012 at 9:03
  • Updated to show most of the code now :) Commented Jul 20, 2012 at 9:09

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

YES! THANK YOU! so very much Puggen, If you take a look at the link, it is showing the results needed, although more but it has the results that needs to be shown thank you so much, I am so very greatfull for your help and assistance.
All sorted Puggen, Again, Please let me Thank you for your time and assistance. I am so much in appriciation for your help! Thank you!
0

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

} 

2 Comments

Hi Puggen, Thank you for your update... As i see it the $blmarArray should have the value of the AGENT_REF of each property. But i'm not able to get the array so i can do an array diff.. The array from mysql results the proper fields adn this is why i'm thinking the array from $blmarArray isn't returning the results i need from the blm file.
we need to know how $rmdata structure looks like, to help you get this right, do as @DonSeba says

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.