Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic page

Status
Not open for further replies.

buztwet

IS-IT--Management
May 1, 2003
46
US
This is what I would like to happen. I have a paragraph that I would like to appear on a page that is different each day. I would like the page to pull the correct document each day without me having to tell it what day it is? How do I do this?
 
Hmm...first thing that comes to mind:

Assuming you're working with PHP---

Say you have seven files:
indexmon.php
indextue.php
indexwed.php
indexthu.php
indexfri.php
indexsat.php
indexsun.php

Say you have one main page:
index.php

Your index.php code can be something like the following:

Code:
<?php
$day_of_week = strtolower(date('D'));   // mon, tue, etc.
header("Location: index" . $day_of_week . ".php");
?>

This calculates the current day of the week (mon, tue, wed, thu, fri, sat, sun) and then redirects the user to the file.

Or, you could include the page:
Code:
$day_of_week = strtolower(date('D'));   // mon, tue, etc.
require_once ("index" . $day_of_week . ".php");

Or, you could store the paragraphs in a database and request them from the database as needed.

Keep in mind that the header function must be called before ANY html is written to the browser.

Note: this could also work with JavaScript as well as many other scripting languages. PHP is just my most comfortable language.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Right now we have our webserver outsourced, so I don't have the ability to use php, etc. We are going to be bringing it in house within the year, but is there a way for me to make this happen without needing server side programs? Javascript maybe?
 
OK! I've come up with a solution. Someone tell me if I suck though - I'm not a huge Javascript person.

So, here's what I did:

Code:
<html>
<head>
<title>Dynamic Paragraphs</title>
<script language="JavaScript">
<!--
function getParagraph() {
    var parArray = new Array(7);
    var the_date = new Date();
    var the_day = the_date.getDay();

    parArray[1] = 'This is the paragraph for Monday';
    parArray[2] = 'This is the paragraph for Tuesday';
    parArray[3] = 'This is the paragraph for Wednesday';
    parArray[4] = 'This is the paragraph for Thursday';
    parArray[5] = 'This is the paragraph for Friday';
    parArray[6] = 'This is the paragraph for Saturday';
    parArray[7] = 'This is the paragraph for Sunday';

    document.getElementById("paragraph").innerHTML = parArray[the_day];	
}
-->
</script>
</head>

<body onload="getParagraph();">
<p>
Here is the paragraph for today:<br><br>
<div id="paragraph"></div>
</p>
</body>
</html>

In the body's onLoad event, the page calls the getParagraph function. This function will calculate the current day of the week (1-7). Then, it will display the paragraph associated with that day of the week between the <div></div> tags that are defined with the id "paragraph".

To make for cleaner code, you could keep the javascript in a separate file (getParagraph.js or something), and just include a reference to it in your <head></head> tags.

Let me know if this is what you're looking for.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
That works great - but is there a way instead of putting all the text in the file that I can reference another file with text in it. So instead of 'This is the paragraph for Monday', I can put a file name in there for it to pull?
 
I don't believe you can "include" files via javascript. You'll have to use server-side includes, or, easier still, have 7 separate files, named index1.html, index2.html, etc.

Then, when index.html loads, have javascript determine the current day of the week, and redirect the user to the appropriate file.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
ok - well thanks for all your help. I can make this work.
 
no problem.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
You could use and iframe note hte different files types.
Code:
<html>
<head>
<title>Dynamic Paragraphs</title>
<script language="JavaScript">
<!--
function getParagraph() {
    var parArray = new Array(7);
    var the_date = new Date();
    var the_day = the_date.getDay();

    parArray[1] = '<iframe src = mon.htm></iframe>';
    parArray[2] = '<iframe src = tues.[COLOR=red]pdf[/color]></iframe>';
    parArray[3] = '<iframe src = Wed.[COLOR=blue]txt[/color]></iframe>';
    parArray[4] = '<iframe src = Thurs.htm></iframe>';
    parArray[5] = '<iframe src = fri.htm></iframe>';
    parArray[6] = '<iframe src = Sat.htm></iframe>';
    parArray[7] = '<iframe src = Sun.htm></iframe>';

    document.getElementById("paragraph").innerHTML = parArray[the_day];    
}
-->
</script>
</head>

<body onload="getParagraph();">
<p>
Here is the paragraph for today:<br><br>
<div id="paragraph"></div>
</p>
</body>
</html>
Hope this helps.

Glen
 
Thank you so much Glen - that works like a charm.
 
Okay, time for me to do some iFrames research...

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top