News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Display List

Started by The Wizard, October 03, 2014, 08:23:10 AM

Previous topic - Next topic

The Wizard

Hello:

My Objective: To display a new word on my web page every Saturday.

Example - the word "Car" would be displayed on my web page until Saturday came around, and
then the next word on the list would replace the word being displayed "Rat" until the next Saturday came around and then the next word on the list would replace the word being displayed, etc...

I have a text file with all the words I want to display and they are in the order I want them to be displayed.

Now here is the catch - it will take 2 1/2 years to get through the list.

I have tried a few different approaches, but have gotten nowhere. Below is my latest failed attempt.


$d = date("z,w");
list($dy,$dw) = explode(",", $d);
$week = intval(($dy-$dw)/7);
if(($dy-$dw)%7) ++$week;

$words = file('wordlist.txt'); // one word per line

$new_word = $words[$week];

echo 'The new word is:<br />';
echo $new_word;


Any help would be gratefully appreciated.

Thanks

The Wizard

margarett

You always need to numerate the sequence of words and (maybe not) memorize the current sequence number so that you can increase it every week

Explode your file into an array then have "week" being the key of the current work ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

The Wizard

Below is a simple script that takes the words and separates them, but how do I only show one word every Saturday?


$array = 'Superman, Batman, Green Arrow, Iron man';

$parts = explode(',', trim($array));

for ($i = 0; $i < count($parts); ++$i)
{
echo $parts[$i],'<br />';
}

margarett

Are you working inside SMF?
If so, a scheduled task allows you to do all of that:
* A task that runs once a day
* If today is Saturday, increase and update $modSettings['word_index'] and set $modSettings['word'] with the respective word
   * if not, clear $modSettings['word']

In the template:
* if !empty($modSettings['word'] echo it
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

The Wizard

Are you working inside SMF?

No this will be part of my web site and so it's just a simple php page.

Wiz

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

The Wizard

No database?

Originally I was not planing on it, but maybe that's a good idea.

Wiz

margarett

Yeah because you always need to memorize which index is currently counting...
You can also keep it in a file instead of db
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

The Wizard

This is my latest idea except I am having trouble with the default feature. Anybody have any ideas on how to solve it?

Wiz


$list = array(
'10-03-2014' => 'Superman',
'10-11-2014' => 'Batman',
'10-18-2014' => 'Green Arrow',
'10-25-2014' => 'Iron Man'
);

echo '<br /><br />';

$date = date("m-d-Y");
echo $list[$date];

// default
if ($list[$date]!=$date)
{
echo'this sucks';
}

Advertisement: