Can't pick up a variables data

Can anyone explain here why, $name == $var2 doesnt work, but if I put the text value of $var2 in here $name == “text value of var2” it works fine!!


list($var1, $var2, $var3) = explode("
", $row2['properties']);

echo "var1 = $var1<br>";
echo "var2 = $var2<br>";
echo "var3 = $var3<br>";


//select all the property names from the properties database
$query1 = "SELECT prop_Name FROM properties ORDER BY prop_Name ASC";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);

//build form
echo '<form name="form1" method="post" action="'.$_SERVER["PHP_SELF"].'">';
echo '<input name="sub" type="hidden" value="y">';

//list all the properties with a checkbox for each
while($row1 = mysql_fetch_array($result1)){
		$name = $row1['prop_Name'];
		//echo $var2;
		if($name == $var2){
		$selected = "checked";
		}else{
		$selected = NULL;
		}
		echo "<input name='properties[]' type='checkbox' value='$name'$selected>$name";
		echo "<br>";
}

//end form
echo '<input type="submit" name="Submit" value="Submit">';
echo "</form>";

Help if you can I’ve spent a day and a half on this already!!