2011-01-27 144 views
-2

我有一個100k域名及其標籤的列表。標籤用逗號分隔。如何通過mysql循環?

由於UTF編碼問題,某些標籤的字符較爲粗糙。所以我想擺脫這一點。

所以我想通過我的數據庫中的每個域循環 然後爆炸標記,然後從不需要的字符過濾它 然後將其插入到新表中。

我的表看起來像這樣...

Domain   Tags 
    yahoo.co.jp  yahoo,search,portal,japan,ãƒãƒ¼ã‚¿ãƒ«,検索,news 
    163.com   news,门户,æ–°é—»,portal,网æ˜「,163,china,门户ç 
    qq.com   qq,china,portal,news,im,门户,chinese,web,socialn... 
+2

100K +域,500K +圖片...,而不是知識的單個位。爲什麼不先練習不太多的數字呢? – 2011-01-27 14:26:49

+0

問題標題應該提及PHP。 – 2011-01-27 14:29:42

+1

我不明白你如何插入100k域名,你不知道如何在for循環中選擇它們?或while循環? – 2011-01-27 14:35:30

回答

-2
$query = mysql_query("SELECT * FROM mytable"); 

while ($row = mysql_fetch_array($query)) { 

    $cleanstr = mysql_real_escape_string(cleanChars($row['Tags'])); 
    mysql_update("UPDATE mytable SET Tags = '$cleanstr' WHERE Domain = '$row[\'Domain\']"); 

} 

function cleanChars($str) { 
    //this function will explode the string and clean the chars 
    //use implode after you clean the unwanted characters to convert the array to a string. 
    return $cleanstr; 
} 
-1
$query = "SELECT * FROM [tablename];"; 
$result = mysql_query($query); 
while($r = mysql_fetch_array($result) 
{ 
    $tags = explode($r["Tags"]); 
    //Do your work here 
    $newtags = FilterTags(",", $tags); 
    $tagstring = implode(",", $newtags); 
    $query = "INSERT INTO [NewTableName] (`Domain`, `Tags`) VALUES (\"".$r["Domain"]."\", \"".$tagstring."\")"; 
    mysql_query($query); 
}