【问题标题】:MySQL Text formattingMySQL 文本格式
【发布时间】:2011-09-07 01:37:04
【问题描述】:

伙计们,

我编写了一个小的 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>";

p.s.:当我使用 phpmyadmin 检查数据集时,似乎像德语“ß”这样的特殊字符也没有正确插入到数据库中

【问题讨论】:

标签: php mysql types type-conversion


【解决方案1】:

我建议你使用UTF-8 charset。

你应该将你的表/列字符集设置为utf8_general_ci

然后在您的 PHP 脚本中作为第一个查询启动

SET NAMES 'utf-8'

【讨论】:

    【解决方案2】:

    至于显示数据,西里尔字符的相同问题通过在从数据库获取数据之前运行下一个代码来解决:

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

    根据您的情况使用适当的德语字符集。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-21
      • 2011-09-28
      相关资源
      最近更新 更多