...

View Full Version : Daily update to PHP page



philm
07-17-2008, 12:27 PM
Hi, hope someone can help me, I'm very new to PHP, I am changing the website for the company I work for to so that it is updated daily with customer testimonials (1 new testimonial per day)

How do I update get the site to update on a daily basis with a different testimonial?

I understand some of the basics I am just struggling with how to put it all together.

If someone can point me in the right direction I would be very grateful.

Cheers
Phil

Iszak
07-17-2008, 12:46 PM
You can use a cron job to say go to the database where testimonials are stored and check if there is any new ones if so then get the oldest new one mark it as old then display it until the next cron job is run when the next cron job comes it'll do the same thing.. check for new testimonial if not use the existing one..

mlseim
07-17-2008, 01:05 PM
You could also use PHP to switch the testimonial when someone visits the page.
It will only switch once per day, but is triggered by the first person that visits the page.

You didn't tell us how your testimonials are stored (database, or files?)

If you have a bunch of them each stored as text files, like:
071708.txt
071808.txt

You could use today's date to load the filename that matches the date.
That means you would need to be creating new testimonials all the time.

It might be better to just put a hundred of them in a directory, with
any type of filename and randomly grab one ... make the testimonial
randomly change each time a person visits the page (or refreshes it).

EDIT:
To display one (like the example above) ...

<?php include("071708.txt")?>

Will display that text file wherever you put the PHP include.


.

philm
07-17-2008, 02:34 PM
You could also use PHP to switch the testimonial when someone visits the page.
It will only switch once per day, but is triggered by the first person that visits the page.

You didn't tell us how your testimonials are stored (database, or files?)

If you have a bunch of them each stored as text files, like:
071708.txt
071808.txt

You could use today's date to load the filename that matches the date.
That means you would need to be creating new testimonials all the time.

It might be better to just put a hundred of them in a directory, with
any type of filename and randomly grab one ... make the testimonial
randomly change each time a person visits the page (or refreshes it).

EDIT:
To display one (like the example above) ...

<?php include("071708.txt")?>

Will display that text file wherever you put the PHP include.


.

Thanks both for the input.

My original plan was to store the testimonials in a database, they are not particularly big, 2 paragraphs at most.

Would using txt files be a better way of doing this?

mlseim
07-17-2008, 02:48 PM
This would be a perfect opportunity to learn some MySQL (a good thing to know),
but it would be very much easier and quicker to just use a simple text file.

It really depends on who is maintaining the testimonials.
Is someone adding to the file every day? Do they have easy FTP access
and know how to edit and upload that text file? Are you going to specifically
change it each day, or do a random thing?

If you have a "non techie" person that is updating the list, and needs to do it
online, that complicates the matter because you'll have to create a simple
online editor.

It would be bad if someone needs to add or change these every day or week.
After a couple of weeks, they'll get pretty sick of it and it won't happen anymore.

You can see how this simple idea can escalate into a project where customers
send a testimonial, and your PHP scripting actually stores them in a database and
your client checks "yes" or "no" as to whether or not that testimonial will appear.
That requires PHP/MySQL and a bunch of scripting on your part ... but that system
is pretty much automatic.

philm
07-17-2008, 03:03 PM
Well the idea is to have a bunch of testimonials that we upload as and when the come in. It will be me that adds them to the database.

I am thinking that it might be easier to have this update to a new testimonial as the page is refereshed or when someone new lands on the page.

I like the idea of readers/customers being able to add their own testimonials at some point.

mlseim
07-17-2008, 04:37 PM
Displaying randomly would be easiest.

A text file with each one on it's own line ...

Say this file is called "testimonial.txt":

Your product really helped me out!
This product let my business grow and become a multi-million dollar business.<br />A great program you have!
We started with 10 clients and ended up with 1000 clients in 6 months!

Your PHP script would be like this (at the top of your page "index.php") ...



<?php
$quote = file("testimonial.txt");
shuffle($quote);
?>


Wherever you want to display it on your page, you put this ...

<?=$quote[0]?>

philm
07-29-2008, 04:11 PM
That works perfectly, thanks for your help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum