Quotes
 

Ok, by creating a simple include file that contains all your quotes, you can easily display a random one, or display them all if you like. The following code will show you how to setup the include file and then how to display them as either random quotes, or to display them in a two column table that evenly divides them up. Note however, the format of the display is built into the code and can easily be changed to your own liking if you understand PHP at all. Even if you don't, its only HTML code that you have to add so you can probably figure it out.

Code

Here's how the "quotes.inc" include file should look

<?
$newquotes[] = array(
"author"=>"Bob",
"quote"=>"This is Bob's quote",
"date"=>"December 5th, 2001"
);

$newquotes[] = array(
"author"=>"Tom",
"quote"=>"This is Tom's quote, not Bob's",
"date"=>"December 9th, 2001"
);

return $newquotes;
?>

Here's the code for the random quotes

<?
$quotes = include("quotes.inc"); // Include the quotes

$X = rand(0, count($quotes)-1); // Pick a number, ie. a random quote
print "<br><p>&quot;";
print $quotes[$X]["quote"]; // Display the quote
print "&quot;</p>\n<p align='right'><i>";
if($quotes[$X]["author"] != "") // Check for the existence of an author
print "- "; // If there is an author, print a - before the name
print $quotes[$X]["author"]; // Print author
print "</i><br>";
print $quotes[$X]["date"]; // Print date
print "</p>\n";
?>

Here's the code to display all the quotes in a two column table

<?
// Lists all the quotes in the file in a two column table
$quotes = include("quotes.inc"); // File containing quotes
$size = count($quotes); // Number of quotes
$X = 0; // Counter

// Create a table
print "<table width='600' border='0' cellspacing='4' cellpadding='10'>\n";
print "<tr>\n<td width='274'>\n";

// Loop through the first half of the quotes, rounding up, and display them
while(2*$X < $size) {
print "<p>&quot;";
print $quotes[$X]["quote"];
print "&quot;</p>\n";
print "<p align='right'><font size='2' face='Arial, Helvetica, sans-serif'><i>";
if($quotes[$X]["author"] != "")
print "- ";
print $quotes[$X]["author"];
print "</i><br>\n";
print $quotes[$X]["date"];
print "</font></p>";
$X++;
}

// End first column, start second column
print "\n</td>\n<td width='274'>\n";

// Loop through second half of quotes, remainder, and display them
while($X != $size) {
print "<p>&quot;";
print $quotes[$X]["quote"];
print "&quot;</p>\n";
print "<p align='right'><font size='2' face='Arial, Helvetica, sans-serif'><i>";
if($quotes[$X]["author"] != "")
print "- ";
print $quotes[$X]["author"];
print "</i><br>\n";
print $quotes[$X]["date"];
print "</font></p>";
$X++;
}

// End the table
print "\n</td>\n</tr>\n</table>\n";

?>

Example

Random Quote

"This is Tom's quote, not Bob's"

- Tom
December 9th, 2001

Two Column Table

"This is Bob's quote"

- Bob
December 5th, 2001

"This is Tom's quote, not Bob's"

- Tom
December 9th, 2001