Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
change simple javascript code to PHP code
Old 11-27-2010, 06:00 AM change simple javascript code to PHP code
Junior Talker

Posts: 3
Trades: 0
Hi, I've been playing around with components and modules in articles on joomla to get the things doing just what I want... and to finish it off I either need to get this javascript to work with the php (which probably won't because of server side/client side differences), or change it into php that does the same job...

Quote:
<script language = 'javascript'>
<!--
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var currentyear=year

var ParaMonth=month+1
if (ParaMonth>12)
{var currentyear=year+1
ParaMonth=ParaMonth-12}
var parameter =("&month="+ParaMonth+"&year="+currentyear)//-->
</script>
parameter is what I want to add to the end of a url link on the page... so that the url link contains &month=[thismonth+1]&year=[currentyear], having calculated the year and month correctly from today's date without needing me to manually update several pages.

I'd appreciate any help I can get, thanks!
highab is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-27-2010, 08:09 AM Re: change simple javascript code to PHP code
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
One immediate isssue: Javascript is client-side, php is server-side execution. If you use php you're using the server's time settings, not the "person at the other end's". If you do go with php, getdate gives you an associative array of the various components of a date/time. Note: www.php.net is a great source, even if you're new to php
PaulW is offline
Reply With Quote
View Public Profile
 
Old 11-27-2010, 05:28 PM Re: change simple javascript code to PHP code
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$time mktime(nullnullnulldate('n') + 1);

$month date('n'$time);
$year date('Y'$time);

$query http_build_query(array('month' => $month'year' => $year)); 
As Paul pointed out, the above solution will use the server's time rather than the user's.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to change simple javascript code to PHP code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48179 seconds with 12 queries