www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: server clock

  1. #1
    Join Date
    Jun 2003
    Posts
    181

    server clock

    Hi,
    anybody knows server clock script to get time from server no need to refrsh the page as it will automatically uodated from script when time changes
    from javascript its quite easy how to do from PHP to get server time

    <script language="JavaScript">
    function show(){
    var Digital=new Date()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()

    if (hours<=9)
    hours="0"+ hours
    if (minutes<=9)
    minutes="0"+minutes
    document.tstest.clock.value=hours+":"+minutes

    setTimeout("show()",1000)
    }
    show()

    </script>
    <input type="text" class="button" size="1" name="clock">

    how to get from PHP.

    Thanks

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    It's a little bit tough. You need to get the server time, check the offset from your current time, and use these numbers to adjust the javascript clock, using the Date object in javascript.

    PHP Code:
    <script language="JavaScript">

    function calculate() {

    var serhours = <?PHP echo date("g"?>;
    var serminutes = <?PHP echo date("i"?>;

    var Digital=new Date();
    var hours=Digital.getHours();
    var minutes=Digital.getMinutes();

    if (hours<=9) {
        hours="0"+ hours; 
    }
    if (minutes<=9) {
        minutes="0"+minutes; 
    }

    hrsdif = serhours - hours;
    mindif = serminutes - minutes;

    show();
    }

    function show() { 

    var Digital=new Date(); 
    var hours=Digital.getHours(); 
    var minutes=Digital.getMinutes(); 

    var serhrs = Number(hours) + Number(hrsdif); 
    var sermins = Number(minutes) + Number(mindif); 

    if (serhrs < 0) {
        serhrs = 00;
    }
    if (sermins < 0) {
        sermins = 00;
    }

    document.tstest.clock.value=serhrs+":"+sermins; 

    setInterval("show()",1000); 
    }
    </script>
    <head>
    <body onload="calculate()">
    <form name="tstest">
    <input type="text" size="10" name="clock"> 
    </form>

  3. #3
    Join Date
    Jun 2003
    Posts
    181
    thanks once again but one problem when i am trying to retrieve the value

    <? if ($_POST["clock"] ) {?>
    <?// what shoulid i write to get this server clock value?>
    <? }?>
    for eg.<? echo() ?>

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    PHP Code:
    <?PHP if (isset($_POST["clock"])) {
    echo 
    $_POST["clock"]; #echo the clock.
    ?>

  5. #5
    Join Date
    Jun 2003
    Posts
    181
    function calculate() {

    var serhours = <?PHP echo date("H") ?>;
    var serminutes = <?PHP echo date("i") ?>;

    var Digital=new Date();
    var hours=Digital.getHours();
    var minutes=Digital.getMinutes();

    if (hours<=9) {
    hours="0"+ hours;
    }
    if (minutes<=9) {
    minutes="0"+minutes;
    }

    hrsdif = serhours - hours;
    mindif = serminutes - minutes;

    show();
    }

    function show() {

    var Digital=new Date();
    var hours=Digital.getHours();
    var minutes=Digital.getMinutes();

    var serhrs = Number(hours) + Number(hrsdif);
    var sermins = Number(minutes) + Number(mindif);

    document.tstest.clock.value=serhrs+":"+sermins;

    setTimeout("show()",1000);
    }
    when i am using this script as i want after 12Pm it shows 13,14 and so on but i have seen a strane thing for min.
    its coming negative as 17:-1 and aftr this it become 17:0 and 17:1

    how to over coem this

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Change function show() to something like this:

    Code:
    function show() { 
    
    var Digital=new Date(); 
    var hours=Digital.getHours(); 
    var minutes=Digital.getMinutes(); 
    
    var serhrs = Number(hours) + Number(hrsdif); 
    var sermins = Number(minutes) + Number(mindif); 
    
    if (serhrs < 0) {
        serhrs = 00;
    }
    if (sermins < 0) {
        sermins = 00;
    }
    
    document.tstest.clock.value=serhrs+":"+sermins; 
    
    setInterval("show()",1000); 
    }
    Also, I edited my post above

  7. #7
    Join Date
    Jun 2003
    Posts
    181
    Thanks ...i got one problem i created a colum called Nr and tryin to update everyime i mean to say autoincremented

    $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++;$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++;
    i just want to get value of pk from application but its unable to show the value

    <?echo $_POST["pk"]; ?> //is anything wrong in this code

    thanks in advance

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    $pkResults is an array. Try this:

    PHP Code:
    $row mysql_fetch_assoc($pkResult[0]); #should return the first row in your table 
    If that doesn't work, you'll have to use a loop, but I'd think it would.

  9. #9
    Join Date
    Jun 2003
    Posts
    181
    sorry its not working when i am using
    $row = mysql_fetch_assoc($pkResult[0]);
    and then try to print incremented value like this
    <? echo mysql_fetch_assoc($pkResult)?>
    its showing no value in cleint side and morever how i can give some name to this field as i need name to insert value in database


    but when i try to use this on client side
    <td><input size="1" type="text" name="nr" value="<?= $pk ?>" readonly></td>
    its working fine and showing the result what i want but problem its taking too much space i mean to say size of field width
    2-----this is $pk
    001

    thanks in advance

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Does you id row have the unsigned zerofill attribute set?

  11. #11
    Join Date
    Jun 2003
    Posts
    181
    hi,

    yaa my Nr field have attribute unsigned Zerofill int(3)
    <input type="button" class="button" value="Save" name="Save" border="1" onclick="go();">
    this button submits this nr. value to database for that i need the name of this field,if i use <? echo ($pk) ?> where should i give field name so that it will be helpful for insÚrtion otherwise querry error.
    but when i use ><input size="1" type="text" name="nr" value="<?= $pk ?>" readonly></td>
    then its working fine only problem its taking space

    thanks in advance

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    With zerofill, it will pad the number with 0's. Just remove that, and you should get numbers like 1,2,3 rather than 001,002,003...

  13. #13
    Join Date
    Jun 2003
    Posts
    181
    even though i remove zerofill how i can get name for this field
    <?echo ($nr); ?>the problem is how to get field name not zerofill even if not remove this value is printing
    i got another problem with below script

    <td nowrap>
    <input type="text" class="button" size="1" name="clock">
    <select name="To" size="1" onChange="calculateIst()">
    <option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
    <? fillDD(8, 0, -1); ?>
    </select>
    </td>
    <td>
    <? if ($_POST["To"] != "clock") {?>
    <?= $line["To"] ?>
    <? if (isset($_POST["clock"]))?>//its not going to this loop
    <?echo $_POST["clock"]; ?>
    <? }?>
    </td>

    its getting only value of To field no matter whether user chooses tiem from To or running clock is there,i want something like when user not select anything from To he will get value of clock and if i use this alone
    <? if (isset($_POST["clock"]))?>//getting error
    <?echo $_POST["clock"]; ?>
    <? }?>

    how to overcome this problem

  14. #14
    Join Date
    Jun 2003
    Posts
    181
    hi,

    <?echo ($nr); ?> how to give name something like name='nr'
    in this tag as name is needed for insertion in database.

    thanks

  15. #15
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    huh?

    Is this what you mean?

    PHP Code:
    <?PHP
    echo "name='$nr'";
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles