2015-05-08 34 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

謝謝,我會嘗試 –

相關問題