MySQL整个网站中的符号来自MySQL检索的数据库数据

时间:2016-09-27 05:50:23

标签: php html

所以我不知道为什么,但是当我从离线网站上网时突然网站不会显示任何符号,我不知道为什么。它离线工作得很好。真的无法找到以前从未见过的任何信息:(

enter image description here 我的header.php

<?php
header('Content-Type: text/html; charset=UTF-8');
echo <<<_END

<!DOCTYPE html>
<html>
<head>
    <title>$title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap-theme.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet">
</head>
<body>
_END;

和index.php

<?php
$title = 'Baz Building';
require_once 'header.php';
require_once 'nav.php';
?>
<div class="container">
    <h1>Welcome to baz Build by Richard Hayward</h1><br><br>
    <div class="col-8">
        <h2 class="text-center">Houses</h2>
    </div>
    <div>
        <ul class="list-group">
        <?php
        //Get connection details from file
        require_once'mysqli-con.php';
        //Create new connection
        $conn = new mysqli($hn, $un, $pw, $db); //Create new object, MYSQLI connection
        if ($conn->connect_error) die ($conn->connect_error); //Display error if failed to connect


         // Create first query to get all house names for count
        $query_names = $conn->query('SELECT name FROM house_names'); // Query all names data
        $num_rows = $query_names->num_rows; // Get the number of rows for loop

        //Start loop for output of each item
        for($c = 0 ; $c < $num_rows ; ++$c){

            //Query Join
            $query_names->data_seek($c);
        $name = $query_names->fetch_array(MYSQLI_NUM);

            $query = "SELECT house_names.id, house_names.name, houses_has_features.house_names_id, house_types.type, features.feature FROM house_names
JOIN houses_has_features
ON house_names.id = houses_has_features.house_names_id
JOIN house_types
ON house_types.id = houses_has_features.house_types_id
JOIN features
ON houses_has_features.features_id = features.id
WHERE house_names.name = \"$name[0]\"";


            $query_join = $conn->query($query);

        $rows = $query_join->num_rows;

        echo '<p>';

            //Output name and type for each item
        $first_rows = $query_join->fetch_array(MYSQLI_ASSOC);
        echo '<li class="list-group-item active">' . $first_rows['name'] . '</li>';
        echo '<li class="list-group-item"><b>Type: </b>' . $first_rows['type'] . '</li>';
        echo '<li class="list-group-item"><b>Features: </b>';
        for($j = 0 ; $j < $rows ; ++$j) //Features loop
        {
            $query_join->data_seek($j);
            $row = $query_join->fetch_array(MYSQLI_NUM);

            //Output all features for each item
        echo $row[4] . ', ';
        };
        };


        // Close objects
        $conn->close();
        $query_join->close();
        $query_names->close();


        ?>
        </ul>
    </div>
    </div>
</body>
</html>

3 个答案:

答案 0 :(得分:2)

这篇关于unicode的文章值得一读:The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets

  

关于编码的最重要事实

     

如果你完全忘记我刚才解释的一切,请记住   一个非常重要的事实。拥有一个字符串是没有意义的   不知道它使用什么编码。你再也不能坚持了   在沙滩上,假装“普通”文字是ASCII。

     

没有像纯文本那样的东西。

答案 1 :(得分:1)

检查相对路径,URL是WWW ot,没有www

答案 2 :(得分:0)

好的,所以在阅读该帖子后(感谢链接),我将数据库切换到utf8mb4_bin并取出带符号的条目并再次将它们放回去,发现符号现在显示:)

我也加入了我的标题

感谢所有帮助人员:)