Click to See Complete Forum and Search --> : 2 text boxes, 1 result of texts that DON'T match


72newbie
12-15-2007, 11:06 PM
I've been trying for hours and searching google and searching here and I have not been able to figure out how to do this. I have been able to print the items that match.

Axctually I've been able to print the non-matching items but the results show repeats for every row. I started with php alone then using mysql. Is it even possible?

for example:

box1; red, blue, green, yellow
box2; red, green, yellow, blue, black

print: black

scragar
12-16-2007, 07:09 AM
you could split the results into 2 arrays:
$ar1 = split($_POST['txtbox1'], ",");
$ar2 = split($_POST['txtbox2'], ",");
then using a foreach see if in_array for the result to check if it exists in the other array, echoing it if not:
foreach($ar2 as $tmp){
if(in_array($tmp, $ar1)){
echo "$tmp<br>";
};
};
let me know if you want any more elaboration or anything.

72newbie
12-16-2007, 09:44 AM
hehe, thanks! I had to do this:

<?
$text1 =$_POST['site1'];
$text2 =$_POST['site2'];
$ar1 = explode(" ", $text1, -1);
$ar2 = explode(" ", $text2, -1);

foreach($ar2 as $tmp){
if(in_array($tmp, $ar1)){
echo "$tmp<br>";
};
};
?>

David Harrison
12-16-2007, 04:47 PM
Simplification using the built in functions:<?

$ar1 = explode(" ", $_POST['site1']); // No validation eh?
$ar2 = explode(" ", $_POST['site2']);

$diff = array_diff($ar1, $ar2);
$same = array_intersect($ar1, $ar2);

?>