2011-06-02 90 views
0

Hej guys,MySQL文本格式化

我寫了一個小小的php腳本,它訪問數據庫並簡單地顯示在給定查詢中找到的行。它跟他們迴響了一張桌子,但似乎有一些排版錯誤導致了問題標記。任何暗示我可以做什麼來解決這個問題?下面是截圖:文本格式「>

下面是我使用來獲取和顯示數據

$result = mysql_query($sql); 
     if(mysql_num_rows($result)>0){ 
      echo "<div style='float:top;clear:both;'>"; 
      echo "<table border='1'>"; 
      echo "<th>id</th><th>project</th><th>publisher</th><th>country</th><th>contact</th><th>mail</th><th>agent</th><th>report</th><th>todo</th><th>by who</th><th>done(date,text)</th><th>priority</th>"; 
      while($row = mysql_fetch_array($result)){ 
       echo "<tr>"; 
       echo "<td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td><td>".$row[5]."</td><td>".$row[6]."</td><td>".$row[7]."</td><td>".$row[8]."</td><td>".$row[9]."</td><td>".$row[10]."</td><td>".$row[11]."</td>"; 
       echo "<td><form method='POST' action='insert.php'><input type='submit' name='edit' value='edit'/><input type='hidden' name='hiddenID' value='".$row[0]."' /><input type='hidden' name='hiddenDB' value='".$_POST['db']."' /><input type='hidden' name='hiddenProject' value='".$row[1]."' /><input type='hidden' name='hiddenPublisher' value='".$row[2]."' /><input type='hidden' name='hiddenCountry' value='".$row[3]."' /><input type='hidden' name='hiddenContact' value='".$row[4]."' /><input type='hidden' name='hiddenMail' value='".$row[5]."' /><input type='hidden' name='hiddenAgent' value='".$row[6]."' /><input type='hidden' name='hiddenReport' value='".$row[7]."' /><input type='hidden' name='hiddenTodo' value='".$row[8]."' /><input type='hidden' name='hiddenBywho' value='".$row[9]."' /><input type='hidden' name='hiddenDone' value='".$row[10]."' /><input type='hidden' name='hiddenPriority' value='".$row[11]."' /></form></td>"; 
       echo "</tr>"; 
      } 
      echo "</table>"; 
      echo "</div>"; 

PS代碼:看來特殊字符,如德國的‘SS’也越來越aren¿t插入正確插入數據庫時​​,我檢查使用phpMyAdmin

+0

forogt圖片http://imageshack.us/photo/my-images /6/bugsql.png/ – 2011-06-02 12:51:10

+0

你使用的是utf-8整理嗎? – Kamil 2011-06-02 12:53:39

回答

1

我建議你使用UTF-8字符集。

你應該讓你的表/ colunmn字符集來utf8_general_ci

然後在你的PHP腳本作爲啓動第一次查詢

SET NAMES 'utf-8' 
0

用於顯示數據的數據集,西里爾字符相同的問題是由運行下面的代碼從數據庫獲取數據之前解決:

mysql_query ("set character_set_client='cp1251'"); 
mysql_query ("set character_set_results='cp1251'"); 
mysql_query ("set collation_connection='cp1251_general_ci'"); 

爲您的案例使用適當的德文字符集。