我有一个名为 item_request 的表,它有两个名为 projectmanager 和 createddate 的字段,其时间戳格式为 2012-09-11 17:46:25。
现在我想以另一种形式调用这两个字段,它计算两个不同日期之间的用户条目。日期字段是从时间戳中获取的。这种形式我通过日期时间选择器发送值,格式为 10-12-2012 但是数据库中的值采用不同的格式,即时发送的值采用不同的格式。plzzz 怎么可能帮助我。
这是我的表单的代码:
<?php
include("config.php");
ob_start();
error_reporting(0);
if(!isset($_SESSION[username]))
header("location: index.php");
if(isset($_POST[submit]))
{
$projectmanager=mysql_real_escape_string($_POST['projectmanager']);
$date=mysql_real_escape_string($_POST['date']);
$dateexp = explode("-",$date);
$date = mysql_real_escape_string($dateexp[0]."/".$dateexp[1]."/".$dateexp[2]);
$date1=mysql_real_escape_string($_POST['date1']);
$dateexp1 = explode("-",$date1);
$date1 = mysql_real_escape_string($dateexp1[0]."/".$dateexp1[1]."/".$dateexp1[2]);
echo $queryuser= "select * from item_request where projectmanager=$projectmanager AND (requireddate>=$date AND requireddate<=$date1)";
}
?>
<!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>Project Managers Registrarion</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script language="javascript" type="text/javascript" src="js/datetimepicker.js">
//Date Time Picker script- by TengYong Ng of http://www.rainforestnet.com
//Script featured on JavaScript Kit (http://www.javascriptkit.com)
//For this script, visit http://www.javascriptkit.com
</script>
</head>
<body>
<div class="container">
<div class="header"><a href="#"><img src="images/cherry-new.jpg" width="79" height="93" /></a>
<!-- end .header --></div>
<?php include("rightMenu.php");?>
<div class="content">
<h1>PR Count</h1>
<div style="padding:10px 0px; text-align:center; color:#990000;">
</div>
<form action="" method="post" name="loginform">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Project Managers</td>
<td><select name="projectmanager" style="width:145px;" id="projectmanager" onChange="showUser(this.options[this.selectedIndex].id)">
<option value="">Select</option>
<?php $queryuser= "select * from projectmanagers";
$fetuser1user = mysql_query($queryuser);
while($fetuser = mysql_fetch_array($fetuser1user)){
?>
<option id="<?php echo $fetuser['id']?>" value="<?php echo $fetuser['id']?>"><?php echo $fetuser['projectmanager']?></option>
<?php }
?>
</select></td>
</tr>
<tr>
<td>Date From</td>
<td>
<input id="date" type="text" size="20" name="date" /><a href="javascript:NewCal('date','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
</tr>
<tr>
<td>Date To</td>
<td>
<input id="date1" type="text" size="20" name="date1"><a href="javascript:NewCal('date1','ddmmyyyy')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" id="submit" value="Submit" onClick="return formvalidate();"/>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
<table width="100%" border="1"><tr>
<td width="18%" valign="middle" class="tableheading">PI.No.</td>
<td width="18%" valign="middle" class="tableheading">Project Manager</td>
<td width="18%" valign="middle" class="tableheading">Date Created</td>
<td width="15%" valign="middle" class="tableheading">Action</td>
</tr>
<?php
// to print the records
$select = "select * from item_request";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td class="tabletext"><?php echo $value[id];?></td>
<td class="tabletext"><?php echo $value[projectmanager];?></td>
<td class="tabletext"><?php echo $value[datefrom];?></td>
<td class="tabletext"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $value[id];?>&cmd=edit"><img src="images/edit.png" width="25" height="25" border="0" title="Edit" /></a>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?id=<?php echo $value[id];?>&cmd=delete" onclick="return confirm('Are you sure you want to delete <?php echo $value[projectmanager];?>?')"><img src="images/deleteBtn.png" width="25" height="25" border="0" title="Edit" /></a></td>
</tr><?php }?>
</table>
</form>
<!-- end .content --></div>
<?php include("footer.php");?>
<!-- end .container --></div>
</body>
</html>