|
 |
|
มีปัญหา อยากให้ช่วยเกี่ยวกับวันที่่ครับผม การ +เพื่ม วัน-เวลาปัจจุบันครับ |
|
 |
|
|
 |
 |
|
add_product_auction
<?
include("ConnectDB.php");
$customer_id = $_COOKIE['id'];
//echo $customer_id;
?>
<!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>ประกาศประมูลสินค้า</title>
</head>
<body>
<form method="post" enctype="multipart/form-data" action="add_product_auction_code.php">
<table width="100%" align="center" cellspacing="0" border="1">
<tr>
<td width="19%" align="left">ชื่อ</td>
<td width="81%"><input name="txtfName" type="text" value="" maxlength=""/></td>
</tr>
<tr>
<td width="19%" align="left">รูป</td>
<td width="81%"><input type="file" name="btnUpload" value=""/></td>
</tr>
<tr>
<td width="19%" align="left">ประเภท</td>
<td width="81%">
<?
$sql= " SELECT type, type_name FROM type_product";
$query = mysql_db_query($dbname, $sql) or die("Can't Query");
echo "<select name='typeList' id='typeList'>";
echo "<option value='0'>---กรุณาเลือก---</option>";
while($row = mysql_fetch_array($query))
{
echo "<option value='$row[0]'>$row[1]</option>";
}
echo "</select>";
?></td>
</tr>
<tr>
<td width="19%" align="left">รายละเอียด</td>
<td width="81%"><textarea name="description" cols="50" rows="3"></textarea></td>
</tr>
<tr>
<td width="19%" align="left">วันเริ่ม</td>
<td width="81%"><input name="str_date" type="text" id="str_date" value="<?php echo date('Y-m-d H:i:s'); ?>" readonly="readonly" /></td>
</tr>
<tr>
<td width="19%" align="left">อีกกี่วันจะสิ้นสุด</td>
<td width="81%"><input type="text" name="end_date" value=""/></td>
</tr>
<tr>
<tr>
<td width="19%">ราคาขั้นต่ำ</td>
<td width="81%"><input type="text" name="low_price" value=""/></td>
</tr>
<tr>
<td><input type="submit" name="btnSubmit" value="ยืนยัน"/></td>
<td><a href="main.php">ยกเลิก</a></td>
</tr>
</table>
</form>
</body>
</html>
add_product_auction_code
<?
$customer_id = $_COOKIE['id'];
$user = $_COOKIE['user'];
//echo $customer_id;
include('ConnectDB.php');
$name = $_POST["txtfName"];
$type = $_POST["typeList"];
$descrip = $_POST["description"];
$str_date = $_POST["str_date"];
$end_date = $_POST["end_date"];
$low_price = $_POST["low_price"];
if($_FILES["btnUpload"]["name"] != "")
{
if(copy($_FILES["btnUpload"]["tmp_name"],"UploadAuction/".$_FILES["btnUpload"]["name"]))
{
$sql = "
SELECT MAX(auction_id) MAX_AUCTION_ID FROM product_auction
";
$query = mysql_db_query($dbname, $sql) or die("Can't Query");
$auction_id = mysql_fetch_array($query);
$id = $auction_id[0] + 1 ;
$sql= " INSERT INTO product_auction ( auction_id, auction_name, image, type, detail, str_date, end_date, low_price, auction_status, auction_number, date, customer_id )
VALUES ( '$id','$name','".$_FILES["btnUpload"]["name"]."','$type', '$descrip', '$str_date', '$end_date', '$low_price', 'T','0',
now(), '$customer_id' )
";
$query = mysql_db_query($dbname, $sql) or die("Can't Query1");
header("location:main.php");
}
}else
{
echo " <script language='javascript'>
alert('Upload Fail.');
window.location='logout.php';
</script>";
}
mysql_close();
?>
ผมได้มีการกำหนดวัน-เวลาเริ่มต้นเป็นวัน-เวลาเปัจจุบันไว้ครับ ผมอยากให้ USER มาใส่ข้อมูลลงในช่องที่ว่า "อีกกี่วันจะสิ้นสุด" เป็นจำนวนตัวเลขเช่น 3 ก็จะมีการเพิ่มวัน-เวลาสิ่นสุดจากวัน-เวลาเปัจจุบันไปอีก 3 วัน ครับ ผมไม่รู้จะเขียนยังไงครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-02-21 13:49:12 |
By :
tangsupap |
View :
811 |
Reply :
8 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขี้เกียจอ่านจัง ยาว เอาเป็นว่าตอบว่า ทำไงให้ + - วันที่ปัจจุบันนะ
strtotime <!-- ไว้แยก วันที่เป็นตัวหนังสือเพื่อเอามาคำนวน
Code (PHP)
$Date = date("Y-m-d" , strtotime("+3 days" , 'วันใน database'));
ควายหมายของข้างบนคือ
ให้+ ไปอีก 3 วัน จาก database
|
 |
 |
 |
 |
Date :
2011-02-21 14:20:06 |
By :
teez1232002 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อยากให้ user ใส่เองนะครับว่าจะเอาอีกกี่วัน ต้องเขียนยังไงครับ
|
 |
 |
 |
 |
Date :
2011-02-21 14:21:58 |
By :
tangsupap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$Date = date("Y-m-d" , strtotime("+3 days" , 'วันใน database'));
เอาไปประยุกค์ ซิคับ
$Date = date("Y-m-d" , strtotime(<?=input_เข้ามา?> days" , 'วันใน database'));
|
 |
 |
 |
 |
Date :
2011-02-21 14:24:04 |
By :
teez1232002 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$date = $end_date("Y-m-d" , strtotime('<?=end_date?>days' , 'str_date'));
อย่างนี้อะเปล่าครับ ผม error อะ
|
 |
 |
 |
 |
Date :
2011-02-21 14:47:03 |
By :
tangsupap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$date = $end_date("Y-m-d" , strtotime('<?=end_date?>days' , 'str_date'));
str_date คือตัวอะไรเหรอคับ แหละอีกอย่าง end_date จะให้มัน+ หรือ - คับต้องใส่เครื่องหมายไปด้วย
ยกตัวอย่างใน Code เลย
Code (PHP)
<?
echo "TEST CODE";
$NOW = date("Y-m-d");
$end_date = 4; /// ตัวที่ input
echo ">>".$date =date("Y-m-d" , strtotime("+$end_date days" , strtotime($NOW)));
?>
ตัวอย่าง คือ input มา 4 วัน ก็+ จากวันปัจจุบันไปอีก 4 จะออกมา อีก 5 วันถัดไป
|
ประวัติการแก้ไข 2011-02-21 15:03:19
 |
 |
 |
 |
Date :
2011-02-21 15:02:55 |
By :
teez1232002 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากเลยครับ
|
 |
 |
 |
 |
Date :
2011-02-21 15:25:34 |
By :
tangsupap |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าเราจะเพิ่มอีก5ชั่วโมงทำไงครับเปลี่ยนจากdaysเป็นtimeมั้ย
|
 |
 |
 |
 |
Date :
2011-02-22 05:04:10 |
By :
ดน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|