2015-05-08 36 views
-1

我在计算表格内容并将值保存在文件中。当有一个插入到这个表中时,将创建另一个文件,并保存新的计数编号。现在我想获得这个2值并进行比较。我总是得到一个强有力的结果。

这是我的代码:?获取内容文件并将其转换为int php

$crc1 = strtoupper(dechex(crc32(file_get_contents('lastinsert.txt')))); 
$crc2 = strtoupper(dechex(crc32(file_get_contents('newinsert.txt')))); 
if($crc1>$crc2){ 
echo $diff=abs(intval($crc1)-intval($crc2)); 
} 
$querycount="SELECT count(*) from relations"; 
if (filesize('lastinsert.txt') == 0){ 
echo "The file is DEFINITELY empty"; 
} 
else if($crc1!=$crc2){         //if the lastinsert is different from the new one we create the newinsert file 
echo "The file isn't empty"; 
if($query_run= mysql_query($querycount)){ 
    while($query_row = mysql_fetch_assoc($query_run)) { 
$res=print_r($query_row); 
file_put_contents("newinsert.txt",$query_row); 
} 
} 
} 
if($query_run= mysql_query($querycount)){ 
    while($query_row = mysql_fetch_row($query_run)) { 
$res=print_r($query_row); 
file_put_contents("lastinsert.txt",$query_row); 
} 
} 
+0

你的奇怪结果是什么? –

+0

这是结果之一2470247或结果必须是2 –

+0

我强烈建议使用数据库来存储数据。 –

回答

-1

你强的结果意味着什么,我猜你的意思是一个字符串的结果。
会,为将字符串转换成int,只要使用此:

$string_result=(int) $int_result; 

当然也有其他的方式,例如看THIS之一。

+0

我之前已经尝试过,但这是我得到此结果的相同结果54140 –

+0

您有2个不同的字符串,当你将它们转换为int时,它们都是相同的?这很奇怪,因为它从来没有发生过。使用我给你的另一个解决方案,看它是否有效。 –

+0

谢谢,我会尝试 –

相关问题