如题,已爬过许多文章,尝试了很多方式
读取数据库资料,显示出来的中文都变成了问号QQ
以下为程式码:
<?php
//fetch.php
header('Content-Type: text/html; charset=utf-8');
$connect = mysqli_connect("localhost", "root", "12345678", "contact");
mysql_query("SET NAMES 'utf-8'");
mysql_query("SET CHARACTER_SET_CLIENT='utf-8'");
mysql_query("SET CHARACTER_SET_RESULTS='utf-8'");
$output = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM contact
WHERE name LIKE '%".$search."%'
OR gender LIKE '%".$search."%'
OR phone LIKE '%".$search."%'
OR mobile LIKE '%".$search."%'
";
}
else
{
$query = "
SELECT * FROM contact ORDER BY name
";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<table width="805" height="75" border="0" id="test" border: solid #0
00
<tr bgcolor="#A9D6EB">
<th>C_name</th>
<th>C_id</th>
<th>C_phone</th>
<th>C_staus</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["name"].'</td>
<td>'.$row["gender"].'</td>
<td>'.$row["phone"].'</td>
<td>'.$row["mobile"].'</td>
</tr>
' ;
}
echo $output;
}
else
{
echo 'Data Not Found';
}
?>
以下为网页显示画面跟PHPmyadmin:
https://imgur.com/a/jqmBo
https://imgur.com/a/u4ZkE
先谢谢各位大大了~