www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 06-18-2003, 09:38 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #2  
    Old 06-18-2003, 10:24 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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>
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #3  
    Old 06-18-2003, 10:51 AM
    zuzupus zuzupus is offline
    Registered User
     
    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() ?>
    __________________
    arun krishnan
    Reply With Quote
      #4  
    Old 06-18-2003, 10:58 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    PHP Code:
    <?PHP if (isset($_POST["clock"])) {
    echo
    $_POST["clock"]; #echo the clock.
    ?>
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #5  
    Old 06-18-2003, 11:04 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #6  
    Old 06-18-2003, 10:16 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #7  
    Old 06-20-2003, 04:30 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #8  
    Old 06-20-2003, 08:29 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    $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.
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #9  
    Old 06-20-2003, 09:43 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #10  
    Old 06-20-2003, 11:13 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    Does you id row have the unsigned zerofill attribute set?
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #11  
    Old 06-23-2003, 04:00 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #12  
    Old 06-23-2003, 07:53 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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...
    __________________

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
      #13  
    Old 06-23-2003, 08:09 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #14  
    Old 06-24-2003, 03:17 AM
    zuzupus zuzupus is offline
    Registered User
     
    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
    __________________
    arun krishnan
    Reply With Quote
      #15  
    Old 06-24-2003, 08:22 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    huh?

    Is this what you mean?

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

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes 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

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


    All times are GMT -5. The time now is 03:17 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.