Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   random content on page load (https://www.cableforum.uk/board/showthread.php?t=33638422)

ikthius 09-09-2008 08:26

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

AbyssUnderground 09-09-2008 10:13

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.

ikthius 09-09-2008 17:48

Re: random content on page load
 
Quote:

Originally Posted by AbyssUnderground (Post 34634529)
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 09-09-2008 21:04

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 10-09-2008 18:21

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.

Graham M 10-09-2008 18:43

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");

ikthius 10-09-2008 20:36

Re: random content on page load
 
Quote:

Originally Posted by Graham M (Post 34635401)
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


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

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