moin
ich hab ein kleines programmier-problem. vielleicht mag mir hier jemand helfen...
ich versuch mich jetzt schon seit stunden an einen stundenzähler (wortspiel
). ich möchte die stunden eines arbeitstages aus verschieden projekten addieren und dann die gesammtstunden einer woche ausgeben.
das funktioniert auch, wenn ich bei einem projekt bleibe. sobald es aber mehr als ein projekt ist, geht es nicht (mysql-query mit "LIMIT" > 1)
bin mir schon ziemlich sicher, das das ganze übern array laufen muss, aber mit javascript komm ich nocht nicht so ganz zurecht. ich hatte auch schon teilerfolge mit array.push(), aber bei jedem mausklick hat er weiter addiert ...
vielleicht ist es auch ganz simpel, aber ich komm ned drauf. ich wäre dankbar für ne kleine gedankenstütze!
hier mal das script, so wie es mit einem projekt läuft
ok - habs hinbekommen.![Zwinkern ;) ;)](/forum/styles/smilies/wink.gif)
ich hab ein kleines programmier-problem. vielleicht mag mir hier jemand helfen...
ich versuch mich jetzt schon seit stunden an einen stundenzähler (wortspiel
![Zwinkern ;) ;)](/forum/styles/smilies/wink.gif)
das funktioniert auch, wenn ich bei einem projekt bleibe. sobald es aber mehr als ein projekt ist, geht es nicht (mysql-query mit "LIMIT" > 1)
bin mir schon ziemlich sicher, das das ganze übern array laufen muss, aber mit javascript komm ich nocht nicht so ganz zurecht. ich hatte auch schon teilerfolge mit array.push(), aber bei jedem mausklick hat er weiter addiert ...
vielleicht ist es auch ganz simpel, aber ich komm ned drauf. ich wäre dankbar für ne kleine gedankenstütze!
hier mal das script, so wie es mit einem projekt läuft
PHP:
<?
include ('./functions/mysql_connect.php');
?>
<script type="text/javascript">
<!--
function zaehler() {
monday = document.hours.mon.value.replace(/,/, '.');
tuesday = document.hours.tue.value.replace(/,/, '.');
wednesday = document.hours.wed.value.replace(/,/, '.');
thursday = document.hours.thu.value.replace(/,/, '.');
friday = document.hours.fri.value.replace(/,/, '.');
saturday = document.hours.sat.value.replace(/,/, '.');
var ergebnis = monday*1 + tuesday*1 + wednesday*1 + thursday*1 + friday*1 + saturday*1;
document.hours.ausgabe.value = ergebnis;
}
-->
</script>
<div align="center">
<body>
<table>
<tr>
<td></td>
<td>Montag</td>
<td>Dienstag</td>
<td>Mittwoch</td>
<td>Donnerstag</td>
<td>Freitag</td>
<td>Samsatg</td>
</tr>
<form action="./input_hours.php" method=post name=hours>
<?
$result = mysql_query("SELECT * FROM works LIMIt 1");
while ($row = mysql_fetch_object($result)) {
$title = $row->title;
$id = $row->id;
?>
<tr>
<td><? echo $title; ?></td>
<td><input type=text id=mon value="" onfocus="zaehler();"></td>
<td><input type=text id=tue value="" onfocus="zaehler();"></td>
<td><input type=text id=wed value="" onfocus="zaehler();"></td>
<td><input type=text id=thu value="" onfocus="zaehler();"></td>
<td><input type=text id=fri value="" onfocus="zaehler();"></td>
<td><input type=text id=sat value="" onfocus="zaehler();"></td>
</tr>
<?
}
?>
<tr>
<td>Summe<input type="text" name="ausgabe" Value="" onfocus="zaehler();">Stunden</td>
</tr>
</form>
</table>
</body>
</div>
Ergänzung ()
ok - habs hinbekommen.
![Zwinkern ;) ;)](/forum/styles/smilies/wink.gif)
PHP:
<?
include ('./functions/mysql_connect.php');
$result = mysql_query("SELECT * FROM works");
$count = mysql_num_rows($result);
?>
<script type="text/javascript">
<!--
function zaehler() {
var count = "<? echo $count; ?>";
var monday = 0;
var tuesday = 0;
var wednesday = 0;
var thursday = 0;
var friday = 0;
var saturday = 0;
for (var id = 1; id <= count; ++id) {
eval("monday"+id+" = document.hours.mon"+id+".value.replace(/,/, '.');");
eval("monday += monday"+id+"*1");
eval("tuesday"+id+" = document.hours.tue"+id+".value.replace(/,/, '.');");
eval("tuesday += tuesday"+id+"*1");
eval("wednesday"+id+" = document.hours.wed"+id+".value.replace(/,/, '.');");
eval("wednesday += wednesday"+id+"*1");
eval("thursday"+id+" = document.hours.thu"+id+".value.replace(/,/, '.');");
eval("thursday += thursday"+id+"*1");
eval("friday"+id+" = document.hours.fri"+id+".value.replace(/,/, '.');");
eval("friday += friday"+id+"*1");
eval("saturday"+id+" = document.hours.sat"+id+".value.replace(/,/, '.');");
eval("saturday += saturday"+id+"*1");
}
var ergebnis = monday + tuesday + wednesday + thursday + friday + saturday;
document.hours.ausgabe.value = ergebnis;
}
-->
</script>
<div align="center">
<body>
<table>
<tr>
<td></td>
<td>Montag</td>
<td>Dienstag</td>
<td>Mittwoch</td>
<td>Donnerstag</td>
<td>Freitag</td>
<td>Samsatg</td>
</tr>
<form action="./input_hours.php" method=post name=hours>
<?
$data = 1;
$result = mysql_query("SELECT * FROM works");
while ($row = mysql_fetch_object($result)) {
$title = $row->title;
$id = $row->id;
?>
<tr>
<td><? echo $title; ?></td>
<td><input type=text id=mon<? echo $data; ?> value="" onfocus="zaehler();"></td>
<td><input type=text id=tue<? echo $data; ?> value="" onfocus="zaehler();"></td>
<td><input type=text id=wed<? echo $data; ?> value="" onfocus="zaehler();"></td>
<td><input type=text id=thu<? echo $data; ?> value="" onfocus="zaehler();"></td>
<td><input type=text id=fri<? echo $data; ?> value="" onfocus="zaehler();"></td>
<td><input type=text id=sat<? echo $data; ?> value="" onfocus="zaehler();"></td>
</tr>
<?
$data++;
}
?>
<tr>
<td>Summe<input type="text" name="ausgabe" Value="" onfocus="zaehler();">Stunden</td>
</tr>
</form>
</table>
</body>
</div>