What I'm trying to achieve 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 aren't present in the db. (In the database 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).
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>";