lakshay
lakshay

Reputation: 415

implementing a counter/timer in php mysql web application

i have a form which fills a database with an issue , the issue is either 'resolved' or 'notresolved'. I have to make a counter which starts as soon as the form is submitted in the database and the issue status is 'notresolved' yet and when i resolve the issue , i can check the time taken to solve the issue.

how can i implement it ?

here is my code for the form

<html>
<head>
<title> CREATE ISSUE </title>
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>

</head>
<body>
<br /><br /><br />
<div align="center">
<A HREF="case_id.php" onClick="return popup(this, 'notes')">CaseID Generator</A>
</div>

<div align="center">
<br /><br />

<fieldset><legend>
<h2>IT HELP DESK SYSTEM</h2></legend>
<form action="update.php" method="post">
<table border="0" cellpadding="5" cellspacing="5">
<tr>
<td>Issue : </td> 
<td><input type="text" name="issue" size="20" /></td>
</tr>
<?php date_default_timezone_set('Asia/Kolkata'); ?>
<tr>
<td>Date :</td>
<td>&nbsp;<?php echo date("d/m/y"); ?></td>
</tr>

<tr>
<td>Time :</td>
<td>&nbsp;<?php echo date("h:i:s A"); ?> </td>
</tr>

<tr>
<td>Estimated Time :</td>
<td><input type="text" name="estimate" size="20" /></td>
</tr>


<tr>
<td>Status :</td>
<td><input type="radio" name="status" value="resolved" /> Resolved</td>
<td><input type="radio" name="status" value="notresolved" /> Not Resolved</td>
</tr>

<tr id='Rstatus'>
<td>Escalated To</td>
<td><input type="text" name="escalatedto" size="20" /></td>
</tr>


<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$("input[name='status']").change(function() {
$("#Rstatus").toggle(this.value == "notresolved");
});
$("input[name='status']:checked").change();
</script>

<tr>
<td>CaseID</td>
<td><input type="text" name="caseid" size="20" /></td>
</tr>


<tr>
<td>Call Types </td>
<td><select name="types" >
<option value="">-</option>
<option value="servers">Servers</option>
<option value="desktop">Desktop</option>
<option value="peripherals" >Peripherals </option>
<option value="networking">Networking</option>
</select> 
</td>
</tr>

</table>
<br />
<div align=”center”><input type="submit" name="submit" value="LogIssue" /></div>
</fieldset>
</div>
</form>
</body>
</html>

Upvotes: 0

Views: 1137

Answers (2)

user745235
user745235

Reputation:

Well, thinking fast, that is what came to my mind:

$start = date('m/d/Y', $issue['start_date']);
$end = date("m/d/Y");
$days = round((strtotime($end) - strtotime($start)) / (24 * 60 * 60), 0);

Is that what you need?

You can also do this: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff on your MySQL dates, following Rufinus solution.

Upvotes: 1

Ozair Kafray
Ozair Kafray

Reputation: 13539

You can have a column of type TIMESTAMP in your database table and have its default value set as CURRENT_TIMESTAMP.

See the following thread on Stackoverflow:

How do you set a default value for a MySQL Datetime column?

You should also go through Timestamp properties in MySQL.

Upvotes: 0

Related Questions