How to create a Php or Java code for a Internet page to modify a part of the HTML code?
-
I need to create a php or java code, to change a link in a Internet page that I'm making, i have no idea how to do it, cuz i want it to change every day, but i was looking for an automatic way to do it. Let me explain what I'm doing, cuz I'm kinda bad explaining and English is my second language. I'm doing a intro internet page, here i want to create only one link that takes me to 3 different pages, but i want that link to alternate, what i mean is that i want the link to take me to the first page, then after a day (an amount of time) change and start taking me to the second page, and after that change again, and take me to the third page, an do it all over. I don't know if that's possible, that's why I'm asking, if its not possible how can i do it by a certain amount of clicks? or to alternate every time the link is clicked.
-
Answer:
Hello, You could either make the links hardcoded or database driven. You have two approaches to do this: 1) Randomness 2) Sequential The first obvious way to do this is to store each link in an array as follows: ------------------------------ $linkArr = array('link1', 'link2', 'link3'); ------------------------------ Note that the above could be derived by statically writing them down like I did, or fetching them from the database, or from a file. To do it randomly, you can use the rand method and fill in the size of the arrary ------------------------------ echo $linkArr[rand(0,sizeof($linkArr)-1)]; ------------------------------ But a more decent sequential approach would be to take account of how to switch the link every day, or week, or month, even year ... The way I would do is by simple date manipulation. You can do this with anything you wish... http://ca.php.net/date Let me explain how to play with date. We can assume the month starts at Day number 1, and we can find the current day of the month by doing the following: ----------------------------- $currentDay = date("j"); ------------------------------ Now since we have our day, we can prepare our link storage, note: we can either prepare our link array from a database or statically as we stated earlier: Now since we have the current day and the link array you can do the following which will take use of the modulous operator (%) and find out the remainder and grab it from the linkArr. Better viewed here: http://mohamed.mansour.pastebin.com/fa9da1e3 ----------------------------- <?php // Current Day $currentDay = date("j"); // Link array // Grab from db or anywhere else $linkArr = array( ' http://www.m0interactive.com ', ' http://www.yahoo.com ', ' http://www.northernresistance.com ' ); // Choose the current link wrt to day $currentLink = $linkArr[ $currentDay % sizeof($linkArr) ]; // Print it out echo sprintf(' <a href="%s">%s</a>', $currentLink, $currentLink); ?> ------------------------------ Thats it! Every day the day obviously changes this is by using the modulous operator http://en.wikipedia.org/wiki/Modulo_operation which just finds the remainder from the division. In our case, the maximum number of links in our array, and whatever we divide with it (by day) we find the remainder of it. Good Luck
alucitoa... at Yahoo! Answers Visit the source
Other answers
I think you are able to do that. First the link must be a variable, then use Java script to get today's date or time or whatever you want. Do an if-else statement for the link. I'm not a fan of javascript website and don't have much experience with them. Hope that this is sufficient though.
elite_yuugi
Related Q & A:
- How to dynamically create a PHP class name on the fly?Best solution by stackoverflow.com
- how to Create a Java Package from MATLAB Code?Best solution by Stack Overflow
- how to create a new syntax in java?Best solution by Stack Overflow
- How to create a table in PHP with MySQL?Best solution by Stack Overflow
- How to create a loop for below code?Best solution by WordPress
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.