|
|
|
ดึงข้อมูลจากฐานข้อมูลไม่ยอมแสดงเป็นภาษาไทยครับ ไม่รู้ติดทีอะไร |
|
|
|
|
|
|
|
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>
<?php
session_start();
if($_SESSION['UserID'] == "")
{
echo "Please Login!";
exit();
}
if($_SESSION['Status'] != "purcharing")
{
echo "This page for purcharing only!";
exit();
}
?>
<title>Product</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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");
$objDB = mysql_select_db("thaimee");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM product ";
if($_POST["ddlSelect"] != "" and $_POST["txtKeyword"] != '')
{
$strSQL .= " AND (".$_POST["ddlSelect"]." LIKE '%".$_POST["txtKeyword"]."%' ) ";
}
$objQuery = mysql_query($strSQL) or die ("Error 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="center">
<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"class= "button"></th>
</tr>
</table>
</form>
<table width="" border="0" align="right">
<td><form id="form2" name="form2" method="post" action="new_product.php">
<input type="submit" name="button2" class="button" id="button2" value="New Product" formtarget="_blank" />
</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>
<?
mysql_close($objConnect);
?>
</body>
</html>
</body>
</html>
หน้า getcode
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<link rel="stylesheet" href="css/style.css">
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','abcd1234','thaimee');
mysql_query("SET NAMES UTF8");
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"thaimee");
$sql="SELECT * FROM product order by Productname asc ";
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>ShelfLife</td>
<td>Flavor</td>
<td>Packing</td>
</tr>";
$i = 1;
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $row['Productname'] . "</td>";
echo "<td>" . $row['Product_description'] . "</td>";
echo "<td>" . $row['Product_thainame'] . "</td>";
echo "<td>" . $row['ShelfLife'] . "</td>";
echo "</td><td>";
echo "<a href='product_flavor.php?FilesID= ".$row['ProductID']."'target='_blank'>Flavor</a>";
echo "</td>";
echo "</td><td>";
echo "<a href='product_packing.php?FilesID=".$row['ProductID']."'target='_blank'>Packing</a>";
echo "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2016-02-10 09:06:46 |
By :
athiwatbuun |
View :
775 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
database ที่ใช้ ได้ set เป็น UTF-8 หรือป่าว?
|
|
|
|
|
Date :
2016-02-10 09:37:23 |
By :
CasanovaKung |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กรณีที่เป็น mysqli ครับ
Code (PHP)
<?php
$serverName = "localhost";
$userName = "root";
$userPassword = "root";
$dbName = "mydatabase";
$objCon = mysqli_connect($serverName,$userName,$userPassword,$dbName);
mysqli_set_charset($objCon, "utf8");
แสดงผลภาษาไทย PHP กับ MySQL ด้วยฟังก์ชั่นของ mysqli (UTF8)
|
|
|
|
|
Date :
2016-02-10 09:38:02 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|