random content on page load
09-09-2008, 08:26
|
#1
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
random content on page load
hey everyone,
I have a question, I am making a website up for someone and they would like random testimonials to show when the page is loaded.
my question really is, what would be the best way to do this?
reason I ask is, I dont know if they will have enough testimonials to warrent a database, but I am not sure as to whether they want clients to add in their own testimonials, plus if this will be moderated.
is there a way to store data like what is said, by who and what company (if any) they work for, so that when I randomise it, I get all of the correct data so this can be viewed on load?
ik
|
|
|
09-09-2008, 10:13
|
#2
|
|
Inactive
Join Date: Oct 2005
Location: Merseyside
Age: 37
Services: BT Infinity Option 2, HH5, synced at maximum 80Mbps/20Mbps.
Posts: 2,221
|
Re: random content on page load
You could have a separate page for each and then some basic php pr javascript to go to one of the random pages. PHP would be better since it works on all computers, but with javascript it would have to be enabled. Here is the PHP I would use.
random.php
PHP Code:
<?php
// 1,4 indicates a number between 1 and 4 will generate on load, edit as necessary with the number of pages $rand = rand(1,4);
// this redirects your browser to the appropriate page based on the random number (in theory!) header("Location: testimonial".$rand.".htm");
// name pages as "testimonial1.htm" and "testimonial2.htm" etc, with a progressing number // as you make new pages. Remember to edit the random number to the number of pages // you have made testimonials for
?>
The script is untested but should work.
|
|
|
09-09-2008, 17:48
|
#3
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: random content on page load
Quote:
Originally Posted by AbyssUnderground
You could have a separate page for each and then some basic php pr javascript to go to one of the random pages. PHP would be better since it works on all computers, but with javascript it would have to be enabled. Here is the PHP I would use.
random.php
PHP Code:
<?php
// 1,4 indicates a number between 1 and 4 will generate on load, edit as necessary with the number of pages $rand = rand(1,4);
// this redirects your browser to the appropriate page based on the random number (in theory!) header("Location: testimonial".$rand.".htm");
// name pages as "testimonial1.htm" and "testimonial2.htm" etc, with a progressing number // as you make new pages. Remember to edit the random number to the number of pages // you have made testimonials for
?>
The script is untested but should work.
|
I had a think about this at work, although I am not up to spead with php, got a book, but its not light reading...
anyway, I was thinking of making a basic page that someone can enter details and storing this as an xml file (and appends to the file), then I could generate a random quote from the xml file, would this work? not looking for links to anything just a testimonial really.
Sorry forgot to say, the testimonials are supposed to be vied in one page that has other info on it.
ik
|
|
|
09-09-2008, 21:04
|
#4
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: random content on page load
I have got a script that reads random text files so far... I found this while searching how to's here: http://uk2.php.net/
PHP Code:
<?php $random = rand(1, 3); $myFile = "$random.txt"; $fh = fopen($myFile, 'r'); $theData = fgets($fh); fclose($fh); echo $theData; ?>
ok, I think I know how I can go about this, ok its going to be a bit of work at the start until I can get an easier user friendly version.
but, is there anyway I can force my area, that I want to echo out to, stay at the size I intended it to be, as with this, the table columnis changing size.
or will this have to be done by using the \n in the text file?
forget that, I am going down teh array route now, as it keeps the page looking fine.
ik
|
|
|
10-09-2008, 18:21
|
#5
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: random content on page load
sorry, could someone who is better at php than me help out with a location statement
I have the php file in the same directory but I want to put it somewhere else, cgi-bin
I cant get the absolute path to work with includes, how can I get it to find the directory...
e.g.
www/a/this.html (php was in this directory)
www/cgi/thephp.php (point to here)
I tried, includes('absolute path'); not working
but all others I tried dont work, but the script in the same directory is working, so its not the file.
|
|
|
10-09-2008, 18:43
|
#6
|
|
-
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+
Tivo
V-Box
VM 60MBit
Posts: 13,365
|
Re: random content on page load
If its a Windows system and you had to use an absolute path you'd need the drive letter too, if its Linux you'll need the full path from the root file system, you can however use a relative path like include("includes/include.php");
|
|
|
10-09-2008, 20:36
|
#7
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: random content on page load
Quote:
Originally Posted by Graham M
If its a Windows system and you had to use an absolute path you'd need the drive letter too, if its Linux you'll need the full path from the root file system, you can however use a relative path like include("includes/include.php");
|
I figured out why it was not seeing it correctly, I had the blooming same php file in the directoy so I think it was confusing
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +1. The time now is 03:59.
|