|
|
|
ตัวอย่าง การแบ่งหน้า (PHP Paging) แบบนี้เอาไปใช้ยังไงคะ โง่จิงๆ |
|
|
|
|
|
|
|
ตัวอย่าง การแบ่งหน้า (PHP Paging) แบบนี้เอาไปใช้ยังไงคะ
http://www.i-keng.com/2009/09/26/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%81%E0%B8%9A%E0%B9%88%E0%B8%87%E0%B8%AB%E0%B8%99%E0%B9%89%E0%B8%B2%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-php-php-paging/
ทำเปนตัวอย่างให้หน่อยนะคะ
ถ้าโค้ดหนูเปนแบบนี้
<?
include("config.php");
?>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>Add Edit Delete Products</title>
<style type="text/css">
body{font-family: verdana, geneva, sans-serif;}
table{border: 1px solid #aaa7a2;-moz-border-radius: 5px 5px 5px 5px;} /* กำหนดสีเส้นขอบตาราง*/
th{background-color:#1a65a8;border: 0px;padding:6px;color: #ffffff; font: 13px Verdana } /* กำหนดสีเส้นขอบตาราง*/
td {border: 0px ;background-color:#f7f4ef;padding:3px;color: black; font: 13px Verdana}
a:link{text-decoration:none;color:#5e8882}
a:visited{text-decoration:none;color:#5e8882}
a:active{text-decoration:none;color:#5e8882}
a:hover{text-decoration:none; color:#20a6c3}
</style>
</head>
<body>
<?
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$images = $_FILES["txtAddProductPic"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["txtAddProductPic"]["name"];
copy($_FILES["txtAddProductPic"]["tmp_name"],"../images/product/".$_FILES["txtAddProductPic"]["name"]);
$strSQL = "INSERT INTO product";
$strSQL .="(ProductID,CatID,ProductName,ProductPic,Model,ProductDate) ";
$strSQL .="VALUES";
$strSQL .="('".$_POST["txtAddProductID"]."','".$_POST["txtAddCatID"]."','".$_POST["txtAddProductName"]."'";
$strSQL .=",'images/product/".$_FILES["txtAddProductPic"]["name"]."' ";
$strSQL .=",'".$_POST["txtAddModel"]."' ";
$strSQL .=",NOW()) ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$images = $_FILES["txtEditProductPic"]["tmp_name"];
$new_images = "Thumbnails_".$_FILES["txtEditProductPic"]["name"];
copy($_FILES["txtEditProductPic"]["tmp_name"],"../images/product/".$_FILES["txtEditProductPic"]["name"]);
$strSQL = "UPDATE product SET ";
$strSQL .="CatID = '".$_POST["txtEditCatID"]."' ";
$strSQL .=",ProductName = '".$_POST["txtEditProductName"]."' ";
if($_FILES["txtEditProductPic"]["name"]){
$strSQL .=",ProductPic = 'images/product/".$_FILES["txtEditProductPic"]["name"]."' ";
}
$strSQL .=",Model = '".$_POST["txtEditModel"]."' ";
$strSQL .=",ProductDate = NOW() ";
$strSQL .="WHERE ProductID = '".$_POST["txtEditProductID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM product ";
$strSQL .="WHERE ProductID = '".$_GET["ProductID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
}
$strSQL = "SELECT `product`. * , `category`.`CategoryName`
FROM `product` , `category`
WHERE `product`.`CatID` = `category`.`CatID` ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" action="<?=$_SERVER["PHP_SELF"].'?pagename=product';?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="hdnCmd" value="">
<table width="500" border="1">
<tr>
<th width="3">No.</th>
<th width="10">ประเภทสินค้า</th>
<th width="15">ชื่อสินค้า</th>
<th width="10">รูปสินค้า</th>
<th width="10">รุ่นสินค้า</th>
<th width="10">วันที่อัพโหลด</th>
<th width="20">Edit</th>
<th width="20">Delete</th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
if($objResult["ProductID"] == $_GET["ProductID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td>
<input type="text" name="txtEditProductID" size="3" value="<?=$objResult["ProductID"];?>">
</td>
<td>
<select name="txtEditCatID" id="txtEditCatID">
<option value="">เลือก</option>
<?
$strSQL = "SELECT * FROM category";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResuut["CatID"];?>" <?= ($objResuut["CatID"] == $objResult["CatID"])? "selected":"";?>>
<?=$objResuut["CategoryName"];?>
</option>
<?
}
?>
</select>
</td>
<td>
<input type="text" name="txtEditProductName" size="15" value="<?=$objResult["ProductName"];?>">
</td>
<td>
<input type="file" name="txtEditProductPic" size="10" value="<?=$objResult["ProductPic"];?>">
</td>
<td>
<input type="text" name="txtEditModel" size="10" value="<?=$objResult["Model"];?>">
</td>
<td>
<input type="text" name="txtEditProductDate" size="10" value="<?=$objResult["ProductDate"];?>">
</td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnUpdate" src="../hmpanel/images/tick.png" width="20" height="20" OnClick="frmMain.hdnCmd.value='Update';">
<input name="btnAdd" type="image" id="btnCancel" src="../hmpanel/images/delete.png" width="20" height="20" OnClick="window.location='<?=$_SERVER["PHP_SELF"];
?>';">
</div></td>
</tr>
<?
}
else{
?>
<tr>
<td><?=$objResult["ProductID"];?></td>
<td><?=$objResult["CategoryName"];?></td>
<td><?=$objResult["ProductName"];?></td>
<td><img src="../<?=$objResult["ProductPic"];?>" width="100" height="100"></td>
<td><?=$objResult["Model"];?></td>
<td><?=$objResult["ProductDate"];?></td>
<td><a href="<?=$_SERVER["PHP_SELF"];?>?pagename=product&Action=Edit&ProductID=<?=$objResult["ProductID"];?>">Edit</a></td>
<td><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?pagename=product&Action=Del&ProductID=<?=
$objResult["ProductID"];?>';}">Delete</a></td>
</tr>
<?
}
}
?>
<tr>
<td><input type="text" name="txtAddProductID" size="2" readonly></td>
<td>
<select name="txtAddCatID" id="txtAddCatID">
<option value="">เลือก</option>
<?
$strSQL = "SELECT * FROM category";
$objQuery = mysql_query($strSQL);
while($objResuut = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResuut["CatID"];?>" <?= ($_POST['CategoryName'] == $objResuut["CatID"])? "selected":"";?>>
<?=$objResuut["CategoryName"];?>
</option>
<?
}
?>
</select>
</td>
<td><input type="text" name="txtAddProductName" size="15" ></td>
<td><input type="file" name="txtAddProductPic" size="10"></td>
<td><input type="text" name="txtAddModel" size="10" ></td>
<td><input type="text" name="txtAddProductDate" size="5" readonly></td>
<td colspan="2" align="right">
<div align="center">
<input name="btnAdd" type="image" id="btnAdd" src="../hmpanel/images/add.png" width="20" height="20" OnClick="frmMain.hdnCmd.value='Add';">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<?php ob_end_flush(); //ส่งข้อมูลที่อยู่ในบัฟเฟอร์ไปให้บราวเซอร์ ?>
Tag : PHP
|
|
|
|
|
|
Date :
2011-12-30 12:12:18 |
By :
Poster |
View :
1274 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เค้อ ขอบคุนนะคะ
|
|
|
|
|
Date :
2011-12-30 13:54:56 |
By :
Poster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ยังทำไม่ได้เลยอ่า
|
|
|
|
|
Date :
2011-12-30 16:11:06 |
By :
Poster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เขาก็บอกไว้นิครับ วิธีใช้งาน
|
|
|
|
|
Date :
2011-12-30 16:38:45 |
By :
ikikkok |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|