문제

Could someone please take a look and let me know what i'm doing wrong... What i'm trying to acheive is, in the Database i have:

AGENT_REF = 1
AGENT_REF = 2
AGENT_REF = 3
AGENT_REF = 4
AGENT_REF = 5

In a file uploaded that parses information

$blmarArray = array($agentref);

AGENT_REF = 1
AGENT_REF = 2
AGENT_REF = 3
AGENT_REF = 5

What i'd like to happen is to extract the AGENT_REF from the database that ISN'T in the file uploaded, in this case AGENT_REF = 4 so i can DELETE it from mysql.

$sql_archeck = mysql_query("SELECT `AGENT_REF` FROM `eprentals`");
$archeck = mysql_fetch_array($sql_archeck);
$sqlarArray = array($archeck);
$combyArrayDiff = array_diff($blmarArray, $sqlarArray);
print_r ($combyArrayDiff);

All i'm getting is the last or first AGENT REF from the database and not the ones that arn't present in the db. (In the db there is 11 but the file uploaded only 8 are present, so i'd like to delete (SHOW) the ones that are in the DB that have been removed from the file uploaded)

Hope you can offer me some guidance into where i'm wrong with this and I Thank you for your time and appriciate your help!

도움이 되었습니까?

해결책

from php manual:

Returns an array containing all the entries from array1 that are not present in any of the other arrays.

so insted of array_diff($blmarArray, $sqlarArray) you should use array_diff($sqlarArray, $blmarArray)

= the big array as first parameter, and the samller array as 2nd parameter


you also need to fetch all rows from the database, not just the first

$query = "SELECT `AGENT_REF` FROM `eprentals`";
$resource = mysql_query($query);
$sqlarArray = array();
while($row = mysql_fetch_array($sql_archeck))
{
    $sqlarArray[] = $row['AGENT_REF'];
}
$combyArrayDiff = array_diff($sqlarArray, $blmarArray);

/* debug result */
echo "<p><b>SQL list:</b> " . implode(', ', $sqlarArray) . "</p>";
echo "<p><b>Uploaded list:</b> " . implode(', ', $blmarArray) . "</p>";
echo "<p><b>Diff list:</b> " . implode(', ', $combyArrayDiff ) . "</p>";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top