GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jul-2003, 02:18
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point

ambiguity in time field


hi,

server2.vitodesign.com

have a look at this site how to avoid 0:00 on bis field as u will see clock on Bis and when u click on this clock image and after that u click on save button u will see 0:00 on von field.how to avoid this ambiguity i need the time of bis on von,

starnge thing is when i select som time from bis and click on save then it show same time in von field,hope u will solve this problem as im newbie in PHP area if u like i can send u code for clarity

thanks
  #2  
Old 25-Jul-2003, 03:00
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
Hi, I'm sorry I've not been very helpful recently, it's crazy at work at the moment.

I see what's happening, but I'm not sure why.

Could you provide a link to the source PHP, so I can see what's happening?

GF
  #3  
Old 25-Jul-2003, 03:04
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point
thanks alot for qucik feedback if u modify this code i will be very grateful i wasted full 2days to sort out this problem but unable to find ...

PHP Code:

<?
         include("../settings.php");
         /* Connecting, selecting database */
         $link = mysql_connect("$dbhost", "$dbuser", "$dbpw")
         or die("Could not connect");

         mysql_select_db("$dbuser") or die("Could not select database");

         $query = "SELECT kunde,projektnr from emp_kunde";
    $result = mysql_query($query) or die("Query failed: $query");
         $kunden = array();
         $projekt = array();
         while ($row = mysql_fetch_assoc($result))
         {
          array_push($kunden, $row["kunde"]);
          array_push($projekt, $row["projektnr"]);
         }
         $query = "SELECT hvorgang,uvorgang,status,soll from emp_details ";
    $result = mysql_query($query) or die("Query failed: $query");
         $getrow=  mysql_fetch_array($result);
         $hvorgang = array();
         $uvorgang = array();
         $status = array();
         while ($row = mysql_fetch_assoc($result))
         {
          array_push($hvorgang, $row["hvorgang"]);
          array_push($uvorgang, $row["uvorgang"]);
          array_push($status, $row["status"]);
         }
         $kunden = array_unique($kunden);
         $hprojekt = array_unique($projekt);
         $haupt = array_unique($hvorgang);
         $unter = array_unique($uvorgang);
         $hstatus = array_unique($status);

        if (isset($HTTP_POST_VARS["von"]))
        {
              $nr = $HTTP_POST_VARS["nr"];
            $datum = $HTTP_POST_VARS["datum"];
            $von = $HTTP_POST_VARS["von"];
            $bis = $HTTP_POST_VARS["bis"];
            $kunde = $HTTP_POST_VARS["kunde"];
            $projekt = $HTTP_POST_VARS["projekt"];
            $hVorgang = $HTTP_POST_VARS["hvorgang"];
            $uVorgang = $HTTP_POST_VARS["uvorgang"];
            $text = $HTTP_POST_VARS["text"];
            $ist = $HTTP_POST_VARS["ist"];
            $soll = $HTTP_POST_VARS["soll"];
                 $status = $HTTP_POST_VARS["status"];

                 $query = "INSERT INTO t_emp";
                 $query.="(nr,datum,von,bis,kunde,projekt,hvorgang,uvorgang,text,ist,soll,status) values ";
                 $query.="('$nr','$datum','$von','$bis','$kunde','$projekt','$hVorgang','$uVorgang','$text','$ist','$soll','$status')";
            mysql_query($query) or die("Query failed: Insert new row");
            $updatePK = "UPDATE key_generator set id = $nr where name = 't_emp'";
            mysql_query($updatePK) or die("Query failed: Update field 'nr' (PK)");

        }
                /// this is the place to get soll value but problem is nr. filed always incremented by 2
                $query = "SELECT * FROM t_emp order by nr DESC";
            $result = mysql_query($query) or die("Query failed: Fetch all rows");
                 $query = "SELECT id from key_generator where name = 't_emp'";
                 $pkResult = mysql_query($query) or die("Query failed: Get last Id");
                 $row = mysql_fetch_assoc($pkResult);
            $pk = $row[id];
            $pk++;

                 function fillDD($min, $max, $selected) //selected format 12:30
                 {

            $sel_bits = explode(":", $selected);
                          for($i=$min; $i<24; $i++) {
                   //$i = sprintf('%02d', $i); # set $i to be padded with a 0's  up to 2 characters
                   for($j=$max; $j<60; $j+=5) {
                     $j = sprintf('%02d', $j); # set $j to be padded with a 0's up to 2 characters
                     if($i == $sel_bits[0] && $j == $sel_bits[1]) {
                              print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
                     }
                        else {
                       print("<option value='$i:$j'>$i:$j</option>\n");
                     }
                         }//for($j)
                         } //for($i)
                }

                $arrDay = array ("So", "Mo", "Di", "Mi", "Do", "Fr","Sa");
                $D=$arrDay[date(w)];

?>

[code]
<html>
    <head>
        <title>Log-Zeiterfassung</title>
        <link rel="stylesheet" type="text/css" href="../styles/styles.css" />
                 <script language="JavaScript" src="date-picker.js"></script>
                 <SCRIPT LANGUAGE="JavaScript" src="log.js"></script>
                 <SCRIPT language="JavaScript">
                    function calculateIst()
                    {
                             var time =document.forms["tstest"].elements["von"].value.split(":");
                                 vontime=parseInt(time[0]*60)+parseInt(time[1]);
                        var time1 =document.forms["tstest"].elements["bis"].value.split(":");
                                 bistime=parseInt(time1[0]*60) +parseInt(time1[1])
                              diff=(bistime-vontime)
                                 if(diff<0){
                                 alert("assure that bis is greater than von")
                            return false
                            }
                            min=(diff%60)
                            hrs=(diff-min)/60
                            if (hrs<=9)
                            hrs="0"+hrs
                            if(min<=9)
                            min="0"+min
                    document.forms["tstest"].elements["ist"].value =hrs + ":" + min;
                    }

               </script>


    </head>

  <form name="tstest" action="log.phtml" method="post">
      <body leftmargin="0" topmargin="0"  marginwidth="0" marginheight="0" class="mybar">
      <table border="1" cellspacing="0" cellpadding="0" style="width:100%" name="rsTable" id="rsTable" cols="11">

             <tr bgcolor="#cccccc">
                         <!--<th>&nbsp;</th> -->
                         <!--<th nowrap>Nr.</th>-->
                        <th width="70">Datum</th>
                        <th width="71">Von</th>
                        <th width="71">Bis</th>
                        <th width="54">Kunde</th>
                        <th width="71">Projekt</th>
               <th width="94">H-Vorgang</th>
               <th width="93">U-Vorgang</th>
               <th width="150">Text</th>
               <th width="40">IST</th>
               <th width="40">Soll</th>
                        <th width="53">Status</th>
                        <th width="66">&nbsp;</th>
         </tr>
                    <? if (!isset($HTTP_POST_VARS["Save"])) { ?>
        <tr>
                         <!--<td><a href="edit.phtml"><img src="../img/edit.gif"  border="1"></a></td> -->
                         <input size="1" type="hidden" name="nr" value="<?= $pk ?>">
            <td  nowrap align="center">
                              <input size="7" type="text" name="datum" value="<?=$D?> <?= date("d.m.y") ?>">
                              <a href="javascript:show_calendar('tstest.datum');"><img src="../img/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the date"></a> </td>

                         <td  nowrap align="center">
                            <select name="von">
                             <?if( isset($von) ){
                                     fillDD(0, 0, $bis);
                                 }else{
                                                 //Lets try & select the closest time to now.
                               $mins = date('i');
                               $mins -= ($mins % 5);  //subtracts the remainder when divided by 5, from the original number

                               fillDD(0, 0, date('H') . ":" . $mins);
                             } ?>
                           </select>
                                <img src="../img/clock.gif" onclick="inputTime();calculateIst()" width="16" height="16"  alt="Clock"></td>

            <td  nowrap align="center">
                              <!--<input type="text" size="1" class="button" name="clock">-->
                              <select name="bis" onchange="calculateIst()">
                                     <option  value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
                    <? fillDD(0, 0, -1); ?>
                              </select>
                              <img src="../img/clock.gif" onclick="insertTime();calculateIst()" width="16" height="16"  alt="Clock"></td>

            <td  nowrap align="center">
                             <select name="kunde" onchange="redirect(this.options.selectedIndex)">
                                <? foreach($kunden as  $value) { ?>
                                <option value="<?= $value ?>" <? if ($HTTP_POST_VARS['kunde'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
                                 <? } ?>
                             </select></td>

            <td  nowrap align="center">
                             <select name="projekt">
                                 <? foreach($hprojekt as  $value) { ?>
                                  <option value="<?= $value ?>" <? if ($HTTP_POST_VARS['projekt'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
                                  <?  } ?>
                             </select></td>

                         <td nowrap align="center">
                             <select name="hvorgang" onchange="redirect1(this.options.selectedIndex)">
                                 <? foreach($haupt as  $value) { ?>
                                 <option value="<?= $value ?>" <? if ($HTTP_POST_VARS['hvorgang'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
                                 <? } ?>
                             </select> </td>

            <td  nowrap align="center">
                             <select name="uvorgang">
                                 <? foreach($unter as  $value) { ?>
                                 <option value="<?= $value ?>" <? if ($HTTP_POST_VARS['uvorgang'] == $value){ echo "SELECTED";}?>><?= $value ?></option>
                                 <? } ?>
                        </select>  </td>

                         <td  nowrap align="center">
                             <textarea name="text" WRAP=SOFT  class="mybar" id="tar" cols="20" rows="1" onfocus="tarea();" onblur="tarea();" title=""></textarea>
                             <img src="../img/edit.gif" onclick="window.open('thewindow.html','newWin','width=150,height=130,top=525,left=800,dependent=yes,alwaysRaised=yes,resizable=1')" width="16" height="16" border="0" alt="Edit Text"></td>

            <td nowrap bgcolor="#cccccc" align="center"><input size="1" type="text" value="00:00" name="ist" readonly></td>

            <td nowrap bgcolor="#cccccc" align="center"><input size="1" type="text" name="soll" value="<?= $getrow["soll"] ?>" readonly></td>

                         <td  nowrap align="center">
                             <select name="status">
                                  <? foreach($hstatus as  $value) { ?>
                                 <option selected value="<?= $value ?>"><?= $value ?></option>
                                 <? } ?>
                        </select> </td>


                         <td  nowrap align="center"><input type="button"  value="Save" name="Save" border="1" onclick="go();"></td>

          </tr>

               <? } ?>

                    <? while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                       $output = wordwrap($line['text'], 20,"<br />", 1);
                    ?>

             <tr bgcolor="#FACB84">
            <!--<td>&nbsp;</td>-->
                        <!-- <td><?= $line["nr"] ?></td> -->
            <td  align="center"><?= $line["datum"] ?></td>
            <td  align="center"><?= $line["von"] ?></td>
                         <td  align="center"><?= $line["bis"] ?></td>
                         <td  align="center"><?= $line["kunde"] ?></td>
            <td  align="center"><?= $line["projekt"] ?></td>
            <td  align="center"><?= $line["hvorgang"] ?></td>
            <td  align="center"><?= $line["uvorgang"] ?></td>
            <td  align="center"><?echo $output;?></td>
            <td  align="center"><?= $line["ist"] ?></td>
            <td  align="center"><?= $line["soll"] ?></td>
                         <td  align="center"><?= $line["status"] ?></td>
            </tr>
              <? } ?>
           </table>

    </body>
         <script language="javascript" src="triplecombo.js"></script>

        </form>

           <script language="JavaScript">
            function go(){
            var myindex=document.forms["tstest"].bis.selectedIndex;
       if (myindex==0) {
       alert("\nPlease be sure that time from bis drop-down menu is selected.");
            }
            else {
            document.tstest.submit(); }
            }//submit go()
            /*var times = new Array ();
       function createArray() {
         for (i=0; i<document.tstest.bis.length; i++) {
               times[times.length] = new Option(document.tstest.bis[i].value, document.tstest.bis[i].value);
         }
        } */
             var x = 0;
             function insertTime() {
            time = new Date();
            hour = time.getHours();
            minute = time.getMinutes();
            hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
            minute = minute.toString().length < 2 ? "0"+minute : minute;
                         if (x==1) {
            document.tstest.bis.options[document.tstest.bis.length-1] = null;
                }
                         var anOption = new Option(hour+":"+minute, hour+":"+minute);
            document.tstest.bis.options[document.tstest.bis.options.length] = anOption
            x = 1;
            document.tstest.bis.options.selectedIndex = document.tstest.bis.options.length-1;

        }
             var y = 0;
             function inputTime() {
            time = new Date();
            hour = time.getHours();
            minute = time.getMinutes();
            hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
            minute = minute.toString().length < 2 ? "0"+minute : minute;
                         if (y==1) {
            document.tstest.von.options[document.tstest.von.length-1] = null;
                }
                         var anOption = new Option(hour+":"+minute, hour+":"+minute);
            document.tstest.von.options[document.tstest.von.options.length] = anOption
            y = 1;
            document.tstest.von.options.selectedIndex = document.tstest.von.options.length-1;

        }

             function tarea()
        {
             if(document.getElementById)
             {
                     if(document.getElementById("tar").rows == 3)
                     {
                             document.getElementById("tar").rows = 1
                             a = document.getElementById("tar").value
                             //a = a.substring(10)

                             if(a)
                             {
                                     document.getElementById("tar").title =  a
                             }
                             else
                             {
                                     document.getElementById("tar").title = ''
                             }
                     }
                     else
                     {
                             document.getElementById("tar").rows = 3
                             document.getElementById("tar").title = ''
                     }
             }
        }


           </script>

</html>
[/code]

<?
    mysql_free_result($result);
    mysql_close($link);
?>

Attached Images
File Type: jpg time.jpg (35.6 KB, 5 views)
  #4  
Old 25-Jul-2003, 10:39
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
Okay, problem 1.

The reason that 0:00 is coming up, when you look at the HTML, is that there is no option being selected. So the problem is in fillDD() function.

When you click the clock, you get the exact time, which is added to the bottom of the dropdown. This time is not always a multiple of 5, like all the other times in the list.

Then have a look at fillDD()
PHP Code:

function fillDD($min, $max, $selected) //selected format 12:30
                 {

            $sel_bits = explode(":", $selected);
                          for($i=$min; $i<24; $i++) {
                   //$i = sprintf('%02d', $i); # set $i to be padded with a 0's  up to 2 characters
                   for($j=$max; $j<60; $j+=5) {
                     $j = sprintf('%02d', $j); # set $j to be padded with a 0's up to 2 characters
                     if($i == $sel_bits[0] && $j == $sel_bits[1]) {
                              print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
                     }
                        else {
                       print("<option value='$i:$j'>$i:$j</option>\n");
                     }
                         }//for($j)
                         } //for($i)
                } 


When you click the clock, you get something like 2:14. The 2 loops run ($i and $j) but the $j loop looks for equality when 14==5 or 10 or 15. So the if statement is never true, and nothing is set to true.

So I suggest you change the IF to the following:
PHP Code:

if($i == $sel_bits[0] && $j <= $sel_bits[1] && $j+5 > $sel_bits[1]) {
      print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
}
else {
      print("<option value='$i:$j'>$i:$j</option>\n");
} 



This should correct the first problem.


The second problem needs a lot more work from you. To keep hold of information that a person submits after they log out & in again, you'd have to create a user accounts system. So every person has to log in with a username & password. That takes work!

Have a look at this, and see what you think:
www.desilva.biz

GF
P.S. I'll be away for the weekend, but I'll try keep up with this thread, ok?
  #5  
Old 28-Jul-2003, 01:31
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point
thank you very much,i dont understand this line

if($i == $sel_bits[0] && $j <= $sel_bits[1] && $j+5 > $sel_bits[1])
what this $sel_bits doing....

thanks once again
arun
  #6  
Old 28-Jul-2003, 02:17
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point
hi,
what happening when first time i log in it give correct time in von field after form submission for eg.

Von Bis
10:00 10:02 //this is fine when first time i submit the form
9:50 10:00

but next time(second time form submission) when i clcik clock image in bis field and submit form im getting 2 min less in von field for eg.

Von Bis
10:00 10:07// 2 min less as it must be 10:02
10:00 10:02

PHP Code:

[color=royalblue]

function fillDD($min, $max, $selected) 
{
$sel_bits = explode(":", $selected);
           for($i=$min; $i<24; $i++) {
       for($j=$max; $j<60; $j+=5) {
                     $j = sprintf('%02d', $j); 
 if($i == $sel_bits[0] && $j <= $sel_bits[1] && $j+5 > $sel_bits[1]) {
 print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
              }
                else {
      print("<option value='$i:$j'>$i:$j</option>\n");
              }
                         }//for($j)
                         } //for($i)
                }
[/color]

[color=orange]
<td  nowrap align="center">
        <select name="von">
         <?if( isset($von) ){
          fillDD(0, 0, $bis);
              }else{
                     //Lets try & select the closest time to now.
                       $mins = date('i');
          fillDD(0, 0, date('H') . ":" . $mins);
             } ?>
        </select>
       <img src="../img/clock.gif" onclick="inputTime();calculateIst()" width="16" height="16"  alt="Clock">
</td>

<td  nowrap align="center">
 <select name="bis" onchange="calculateIst()">
<option  value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>//shows time of server as PHP stuff is there and im using local machine to get value
   <? fillDD(0, 0, -1); ?>
   </select>
 <img src="../img/clock.gif" onclick="insertTime();calculateIst()" width="16" height="16"  alt="Clock">
</td>

[/color] 



hopefully u understand this code dont no why it show 2min or 5 min less in Von field during form submission
  #7  
Old 28-Jul-2003, 02:54
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
OK, first I'd better get this straight: I'm rounding off the times.

If you get 10:02, the next time you view the page it is 10:00. In a time logging application like this, there is no point on being so exact! It just confuses the arithmetic later on.

If you don't want the rounding off, please say.

GF
  #8  
Old 28-Jul-2003, 03:01
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point
yeah exactly no need of round off as whatever the time shown in Bis field(when clicking clock image or selecting time manually)
the exact time must shown in Von field for eg.

11:00 11:03//this time i get when click on image and now when i click on save button next time
11:03 11:10//system time

and i also dont understand why u reduce 5 min in von field
$mins = date('i');
$mins -= ($mins % 5);

thanks alot for your understanding

regards
  #9  
Old 28-Jul-2003, 07:59
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
PHP Code:

$mins -= ($mins % 5); 


That line rounds down the result to the nearest multiple of 5. So 13:17 goes to 13:15. Remove it, and it'll act as you want.

GF
  #10  
Old 28-Jul-2003, 08:40
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point
thanks alot its really appreciable-------
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display Size and maybe download time BobbyDouglas MySQL / PHP Forum 5 08-Nov-2003 00:18
finding time efficiency of STL goathens CPP / C++ Forum 1 28-Sep-2003 17:41
text field problm zuzupus Web Design Forum 3 04-Sep-2003 05:18
time Problem zuzupus MySQL / PHP Forum 9 24-Jul-2003 07:02
The Google update this time... JdS Search Engine Optimization Forum 5 04-Jun-2003 15:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:04.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.