如題,已爬過許多文章,嘗試了很多方式
讀取資料庫資料,顯示出來的中文都變成了問號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
先謝謝各位大大了~