Hi! I'm a bit of a beginner at PHP, and I'm having trouble comparing two strings in a conditional statement. Both of the variables are strings, but one of them them is assigned from a MSSQL database. In this database, it of the unicode varchar data type. It doesn't seem like this should make a difference, but for some reason, whenever I try to compare the two dates, I get a false return value, even when the dates are equivalent.
Here's my code:
//Set database access variables
$host ='mssql.library.uiuc.edu';
$user = 'BEL_webuser';
$pass ='NeUn72L';
$db = 'BEL';
//Open connection
$connection = mssql_connect($host, $user, $pass) or die("Unable to connect");
//Select database
mssql_select_db($db) or die("Unable to select database");
// create query
//$query = "SELECT computer, time, netid FROM bloomberg WHERE(date=N'$date') AND (computer=N'$comp')";
$query = "SELECT * FROM bloomberg";
// execute query
$result = mssql_query($query) or die ("Error in query");
$date1 = '11-05-2007';
for($i = 0; $i < mssql_num_rows($result); $i++){
$row = mssql_fetch_array($result);
$date2 = $row['date'];
if($date1 == $date2){
$dateflag = 1;
}
else {
$dateflag = 0;
}
echo $dateflag;
}
Thanks,
David