/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 18.2003 — 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.

[code=php]<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> [/code]
Copy linkTweet thisAlerts:
@zuzupusauthorJun 18.2003 — 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() ?>
Copy linkTweet thisAlerts:
@pyroJun 18.2003 — [code=php]<?PHP if (isset($_POST["clock"])) {
echo $_POST["clock"]; #echo the clock.
?>
[/code]
Copy linkTweet thisAlerts:
@zuzupusauthorJun 18.2003 — 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
Copy linkTweet thisAlerts:
@pyroJun 19.2003 — Change function show() to something like this:

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 &lt; 0) {
serhrs = 00;
}
if (sermins &lt; 0) {
sermins = 00;
}

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

setInterval("show()",1000);
}
Also, I edited my post above
Copy linkTweet thisAlerts:
@zuzupusauthorJun 20.2003 — 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
Copy linkTweet thisAlerts:
@pyroJun 20.2003 — $pkResults is an array. Try this:

[code=php]$row = mysql_fetch_assoc($pkResult[0]); #should return the first row in your table[/code]If that doesn't work, you'll have to use a loop, but I'd think it would.
Copy linkTweet thisAlerts:
@zuzupusauthorJun 20.2003 — 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
Copy linkTweet thisAlerts:
@pyroJun 20.2003 — Does you id row have the unsigned zerofill attribute set?
Copy linkTweet thisAlerts:
@zuzupusauthorJun 23.2003 — 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
Copy linkTweet thisAlerts:
@pyroJun 23.2003 — 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...
Copy linkTweet thisAlerts:
@zuzupusauthorJun 23.2003 — 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
Copy linkTweet thisAlerts:
@zuzupusauthorJun 24.2003 — hi,

<?echo ($nr); ?> how to give name something like name='nr'

in this tag as name is needed for insertion in database.

thanks
Copy linkTweet thisAlerts:
@pyroJun 24.2003 — huh?

Is this what you mean?

[code=php]<?PHP
echo "name='$nr'";
?>[/code]
Copy linkTweet thisAlerts:
@zuzupusauthorJun 24.2003 — sorry for ur inconvenience i think i m not able to explain u clearly

<td nowrap bgcolor="#cccccc"><?echo "name='$nr'";?></td>


i am using tabel to print nr. let say 001 but with above PHP tag it will print name =" not the value

$query = "SELECT nrFROM 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++;

and i m using in <td>

<input size="1" type="text" name="nr" value="<?= $pk ?>" readonly>

pk value is incremented from database when user login everytime he get incremented and i dont want to use text field as it take more space

i want some thing like <?echo ($pk) name='nr'?>

hope this will be clear

thanks
×

Success!

Help @zuzupus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...