|
![](/images/resource/spacer.gif) |
|
หน้าเว็บแสดงผลภาษาไทยได้ แต่ดึงขอมูลจาก Database ที่เป็นภาษาไทยมาแสดงผลไม่ได้แต่ภาษาอังกฤษกลับแสดงได้ |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ทำระบบค้นหาครับ แล้วนำค่าที่อยู่ตารางเดียวกันใน Dadabase มาแสดงผลในหน้าเว็บ [ตามภาพ]
![t t](https://www.thaicreate.com/upload/stock/20150429230259.png?v=1001)
ค้นหาคำว่า thailand ผลลัพธ์ แสดงดังภาพ
![ด ด](https://www.thaicreate.com/upload/stock/20150429230632.png?v=1001)
แต่พอค้นหาคำอื่นที่เป็นภาษาไทย แล้วมันไม่แสดงผลคับ ทั้งที่อยู่ในตารางเดียวกัน
ค้นหาคำว่า "การสร้างเว็บไซต์อย่างง่าย" ผลลัพธ์ แสดงดังภาพ
![gg gg](https://www.thaicreate.com/upload/stock/20150429231132.png?v=1001)
ไม่ทราบว่าสาเหตุเกิดจากอะไรหรอคับ แล้วมีวิธีแก้ไขอย่างไรบ้างครับ
Code (Search.php)
<?php
include("connection.php");
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_blank" href="urlString">';
$html .= '<h3>nameString</h3>';
$html .= '</a>';
$html .= '</li>';
// Get Search
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$search_string = mysql_real_escape_string($search_string);
// Check Length More Than One Character
if (strlen($search_string) >= 1 && $search_string !== ' ') {
// Build Query
$query = 'SELECT * FROM shop_data WHERE shop_name LIKE "%'.$search_string.'%"';
// Do Search
$result = mysql_query($query);
//exit;
while($results = mysql_fetch_array($result)) {
$result_array[] = $results;
}
//exit;
// Check If We Have Results
if (isset($result_array)) {
foreach ($result_array as $result) {
// Format Output Strings And Hightlight Matches
//
$display_name = preg_replace("/".$search_string."/i", "<b class='highlight'>".$search_string."</b>", $result['shop_name']);
$display_url = 'http://google.com';
// Insert Name
$output = str_replace('nameString', $display_name, $html);
// Insert URL
$output = str_replace('urlString', $display_url, $output);
// Output
echo($output);
}
}else{
// Format No Results Output
$output = str_replace('urlString', 'javascript:void(0);', $html);
$output = str_replace('nameString', '<b>ไม่พบหนังสือที่ค้นหา</b>', $output);
$output = str_replace('funcStr', 'Sorry :(', $output);
// Output
echo($output);
}
}
?>
Tag : PHP, MySQL
![](/images/adv.jpg?v=1001)
|
ประวัติการแก้ไข 2015-04-29 23:15:44
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-04-29 23:14:40 |
By :
indy |
View :
990 |
Reply :
2 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
// Get Search
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$search_string = mysql_real_escape_string($search_string);
บันทัดสีแดง ทุกอักขระที่ ไม่ไช่ พยัญชนะภาษาอังกฤษและตัวเลขอารบิค จะถูกแทนที่ด้วย วรรค
แล้วภาษาไทยที่ใส่เข้าไปจะยังคงอยู่ไหมครับ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2015-04-30 02:28:55 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 01
|