Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | random content on page load

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion
Register FAQ Community Calendar

random content on page load
Reply
 
Thread Tools
Old 09-09-2008, 08:26   #1
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Advertisement
Old 09-09-2008, 10:13   #2
AbyssUnderground
Inactive
 
Join Date: Oct 2005
Location: Merseyside
Age: 37
Services: BT Infinity Option 2, HH5, synced at maximum 80Mbps/20Mbps.
Posts: 2,221
AbyssUnderground has reached the bronze age
AbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze ageAbyssUnderground has reached the bronze age
Send a message via MSN to AbyssUnderground
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.
AbyssUnderground is offline   Reply With Quote
Old 09-09-2008, 17:48   #3
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
Re: random content on page load

Quote:
Originally Posted by AbyssUnderground View Post
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
ikthius is offline   Reply With Quote
Old 09-09-2008, 21:04   #4
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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(13);
$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
ikthius is offline   Reply With Quote
Old 10-09-2008, 18:21   #5
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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.
ikthius is offline   Reply With Quote
Old 10-09-2008, 18:43   #6
Graham M
-
 
Graham M's Avatar
 
Join Date: Jul 2003
Location: Poole, Dorset
Age: 40
Services: FreeSat+ Tivo V-Box VM 60MBit
Posts: 13,365
Graham M has a pair of shiny starsGraham M has a pair of shiny stars
Graham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny starsGraham M has a pair of shiny stars
Send a message via MSN to Graham M Send a message via Yahoo to Graham M
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");
Graham M is offline   Reply With Quote
Old 10-09-2008, 20:36   #7
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
Re: random content on page load

Quote:
Originally Posted by Graham M View Post
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
ikthius is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:22.


Server: osmium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum