I'm using a very simple code to extract data from a MySQL DB to a CSV file. The code didn't provide the result I expected so I made the code including the query in the CSV file. In a fist part of the code seemes that the variable containing the query result doesn't actually contain any value, but in another part of the code the variable contains the correct value. In short, the same variable seems to contain two values in different part of the code.
$sql="SELECT destinazione AS dest,ndc AS n FROM npitz";
$query = mysql_query($sql);
$q="ERROR";
while($row = mysql_fetch_array($query)) {
$query="DELETE FROM npitz_reduced_tmp WHERE
destinazione='".$row['dest']."' AND
ndc LIKE CONCAT('".$row['n']."','%') AND
ndc NOT LIKE '".$row['n']."'";
if($row['n']='77') $q=$query." - ".$row['n'];
mysql_query($query);
}
The variable $row['n'] should contain the result of the SQL query. After the while loop the variable $q is:
DELETE FROM npitz_reduced_tmp WHERE destinazione='UNITED STATES' AND ndc LIKE CONCAT('','%') AND ndc NOT LIKE '' - 77
The question is: if in the IF statement the value of $row['n'] is '77' why it isn't the same in the $query variable assignment?