|
|
|
ติดปัญหาเรื่องphp ไม่ยอมแสดงภาษาไทยแล้ว ไม่ยอมเรียงหน้า และ search ไม่ได้ |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/navigationmenu.css">
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","getproduct.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body onload="showUser('0')">
<ul id="menu">
<li><a href="main_purchase.php">Main</a></li>
<li>
<a href="#">Purchase</a>
<ul class="hidden">
<li><a href="poall.php"><span>Purchase Order</span></a></li>
<li><a href="Supplier.php"><span>Supplier List</span></a></li>
</ul>
</li>
<li><a href="product.php">Product</a></li>
<li><a href="login.php?action=logout">LOG OUT</a></li>
</ul>
<?
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
mysql_query("SET NAMES UTF8");
$objDB = mysql_select_db("thaimee");
$strSQL = "SELECT * FROM product where 1";
if($_POST["ddlSelect"] != "" and $_POST["txtKeyword"] != '')
{
$strSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' ) ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 5; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$strSQL .=" order by FilesID ASC LIMIT $Page_Start , $Per_Page";
$objQuery = mysql_query($strSQL);
?>
</p>
<table width="200" border="0" align="center">
<tr>
<td><img src="picture/logo.png" width="150" height="100"></td>
</tr>
</table>
<tr>
<form name="frmSearch" method="post" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="599" border="0" align="right">
<tr>
<th>Select
<select name="ddlSelect" id="ddlSelect">
<option>- Select -</option>
<option value="Product_thainame" <?if($_POST["ddlSelect"]=="Product_thainame"){echo"selected";}?>>Product(TH)</option>
<option value="Product_description" <?if($_POST["ddlSelect"]=="Product_description"){echo"selected";}?>>Product description</option>
<option value="Productname" <?if($_POST["ddlSelect"]=="Productname"){echo"selected";}?>>Product name</option>
</select>
Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?=$_POST["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<td><form id="form2" name="form2" method="post" action="new_product.php">
<input type="submit" name="button2" class="button" id="button2" value="New Product" />
</form></td>
</tr>
</table>
<tr> </tr>
<table align="left">
<tr>
<select name="category" class="dropdown" onchange="showUser(this.value)">
<option selected value="0">Show All</option>
<option value="11">Canned Food</option>
<option value="12">Confectionery</option>
<option value="13">Drink</option>
<option value="14">Fruit/ Processed Fruit</option>
<option value="15">Label/Sticker</option>
<option value="16">Meat</option>
<option value="17">Noodles</option>
<option value="18">Others</option>
<option value="19">Packaging</option>
<option value="20">Seafood</option>
<option value="21">Seasoning</option>
<option value="22">Snack</option>
</select>
</tr>
</table>
</tr>
<tr>
<td> </td>
</tr>
<div id="txtHint"></div>
<br>
Total <?php echo $Num_Rows;?> Record : <?php echo $Num_Pages;?> Page :
<?php
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
mysql_close($objConnect);
?>
</body>
</html>
ภาษาไทยไม่ยอมแสดง พอใส่ code เรียงหน้ากับ search ก็ไม่ขึ้น
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
<link rel="stylesheet" href="css/style.css">
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','abcd1234','thaimee');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"thaimee");
$sql="SELECT * FROM product";
if ($q!=0) $sql="SELECT * FROM product WHERE CategoryID = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table class='Thaimeetable'>
<tr>
<td>No.</td>
<td>Name</td>
<td>Description</td>
<td>Product (TH)</td>
<td>Picture</td>
<td>ShelfLife</td>
<td>Flavor</td>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['FilesID'] . "</td>";
echo "<td>" . $row['Productname'] . "</td>";
echo "<td>" . $row['Product_description'] . "</td>";
echo "<td>" . $row['Product_thainame'] . "</td>";
echo "<td>" . $row['FilesID'] . "</td>";
echo "<td>" . $row['ShelfLife'] . "</td>";
echo "<td>" . $row['FilesID'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2016-01-28 17:13:14 |
By :
athiwatbuun |
View :
828 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
mysql_query("SET NAMES UTF8");
$objDB = mysql_select_db("thaimee");
ลองสลับ
Code (PHP)
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
$objDB = mysql_select_db("thaimee");
mysql_query("SET NAMES UTF8");
แล้วรันดูครับว่าได้ไหม๊
|
|
|
|
|
Date :
2016-01-28 17:16:51 |
By :
nut_ch31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดู Collation ของ Table มันเป็นแบบ UTF-8 หรือเปล่าครับ
|
|
|
|
|
Date :
2016-01-28 17:54:20 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|