Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
A Really easy project, but need help

Posted by tinmanbf (tinmanbf), 10 May 2007
Hi all

I'm trying to do a really simple project but I can't get my head around it as I haven't been doing this very long.

What I want to do is have a really simple MySQL table, it will just have a field called Time that will contain the time in hours.

The idea is to use a form on a website to enter a number (a time in full hours) and then submitting the form will update the time in the database, Counting upwards, or even down. The idea being that the database will allow up to 40 hours of time a week and then once 40 hours are up it will give a message to say no more time avaiable, and also show the time left on the form webpage. At the end of the week the time will reset, or get reset by a command and will start over again.

So basically:

I need to log time, and I can give 40 hours of task time a week, so I want to be able to get people to enter the amout of time they need in a task, eg lets say some one wants 2 hours, I need this deducted from the 40, because I only have 40 hours of time a week, I need to update this so the people filling out the time, know how much time I have left. so when it goes to 0 I have no more task time left until the next week when it gets reset.

I'm sure this is real easy to do, but Im having problems getting my head around it.

Can anyone help me on my way??

Thanks

Ben


Posted by admin (Graham Ellis), 11 May 2007
Ben, are you looking to do this as a web application using something like PHP?   MySQL is great for storing and enterring user data but it is program friendly rather than web friendly.   I fear that answring your question about the SWL query to change a value would be like describing an engine when you need a whole car at this stage ...

Graham

Posted by tinmanbf (tinmanbf), 11 May 2007
I'm using php, I am just starting out so haven't got very far, so far I have set up the database table and written a short script, but this doesn't do any calculations as yet and only adds more rows instead of updating one single row:

<?php
$db_host = "humbug";
$username = "benzen78";
$password = "------";
$DB_name = "benzen78_pn";
$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);

$sql="INSERT INTO Transfer_hours SET
Time='$Time'
";
mysql_query($sql);
echo '<font face="arial,verdana" size=2><B>Hours have been updated!</B><P></font>';

?>

Posted by admin (Graham Ellis), 11 May 2007
I think you want a REPLACE or UPDATE and not an INSERT - have a look at my flashbulb moments page that explains the differences.  

Posted by tinmanbf (tinmanbf), 11 May 2007
Ok this looks as if I've got a bit further but I'm having a problem displaying my timediff data. I want to show the time that is left on the same page as the form that is filled in, I have been able to display the whole table in the process.php scrpit below, but this isn't what I really want to do, the only data I want to see is the result from the timediff command that I run:
Code:
$sql="SELECT timediff(time_allowed, time_used) as time_diff FROM scheduled_time WHERE scheduled_time.id = 1
";

I want to display the result given by running the command above on the same page as my input form.

This is the code I have so far in my process.php that the form data is sent to:

Code:
<?php

$sql="UPDATE scheduled_time SET time_used = addtime(time_used, '$Time') WHERE scheduled_time.id = 1
";
mysql_query($sql);
echo '<font face="arial,verdana" size=2><B>Transfer hours have been updated!</B><P></font>';

$query="select * from scheduled_time";
$result=mysql_query($query);
echo "<table border=1>";
echo "<tr>";
for($i=0;$i<mysql_num_fields($result);$i++)
{
echo "<th>";
echo mysql_field_name($result, $i);
echo "</th>";
}

while($row=mysql_fetch_row($result))
{
echo "<tr>";
for($j=0;$j<$i;$j++)
{
echo "<td>";
echo $row[$j];
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
echo "</table>";

?>




Posted by tinmanbf (tinmanbf), 12 May 2007
All sorted, Thanks for you help



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho