看板 PHP 關於我們 聯絡資訊
如題,已爬過許多文章,嘗試了很多方式 讀取資料庫資料,顯示出來的中文都變成了問號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 先謝謝各位大大了~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.33.79.26 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1515178371.A.77D.html
a0960330: 你的HTML沒有 charset=utf-8 ?01/06 10:03
有加了耶,但還是一樣顯示問號 ※ 編輯: c182796378 (27.247.44.157), 01/06/2018 12:16:47
tkdmaf: 這麼多內容的code是多餘的,在問問題時應該要縮小範圍01/06 13:23
tkdmaf: 你的問題既然是編碼,只要最低限度的測試輸出結果01/06 13:23
tkdmaf: 然後你並沒有告知你資料庫的編碼結構01/06 13:24
tkdmaf: 資料庫方面還有資料庫編碼,資料表編碼………01/06 13:26
資料庫編碼結構是指utf8_unicode_ci嗎?抱歉QQ因為剛開始學php,很多東西都還搞不清 楚... ※ 編輯: c182796378 (27.247.44.157), 01/06/2018 13:31:10 ※ 編輯: c182796378 (114.33.79.26), 01/06/2018 13:46:40
wbc319: 直接連結資料庫 echo 中文那裡...出來的也是問號嗎?01/06 13:51
echo可以顯示中文!但讀取資料就不行 ※ 編輯: c182796378 (27.247.44.157), 01/06/2018 13:59:48 ※ 編輯: c182796378 (27.247.44.157), 01/06/2018 14:00:26
wbc319: ("SET NAMES 'utf-8'"); 是少一個=嗎? 01/06 14:48
JohnRoyer: Study-Area 之前有篇文章有詳細的設定,可以參考 01/06 15:58
JohnRoyer: https://goo.gl/d9TGKd 01/06 15:58
fezexp9987: 話說 mysqli和mysql能混著用@@? 01/06 18:05
fezexp9987: 不過印象中沒有 - 不知道多了行不行 SET NAMES UTF8 01/06 18:16
a0960330: mysqli跟mysql應該不能混著用吧......會不會是你用 01/06 21:31
a0960330: mysqli連接資料庫,可是你卻用mysql設定utf8 01/06 21:31
gpmm: 你資料表的語系是? 01/06 23:11
hiigara: phpmyadmin 裡面下個 show create table customer_data 01/06 23:16
hiigara: 然後把結果印出來給大家看看 01/06 23:16
hiigara: 等等,mysql 的編碼定義應該是 utf8 而不是 utf-8? 01/06 23:18
hiigara: utf8 或 utf8mb4(大部分的表情符號要後者才會動) 01/06 23:19
hiigara: https://imgur.com/Cf0Qhgz 01/06 23:21
crazwade: 資料庫的欄位好像也要設編碼 01/08 16:18
MOONRAKER: 整個資料庫編碼設對就不用逐個設啦 01/08 16:33