laurierobey: (Lego Me)
[personal profile] laurierobey
On the site I'm working on for gneech.com, I'm going to have a box where I load a random quote from [livejournal.com profile] the_gneech's writing. I'm thinking of having the quotes in an XML file, generating a random number, then loading the quote from the XML file that has an ID that matches the random number.

This is the first bit of functionality I'm trying to write in PHP. This is what I have so far:

<?php
// generate a random number
$random_number = mt_rand(1, 3);

// set name of XML file
$file = "quotes.xml";
// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// pull the quote that matches the random number
Edit: I think this might work.$quote = $xml->quote[$random_number]

//print the quote
print "$quote\n";
?>

The code I haven't come up with yet is the part where I say, "Give me the quote with the ID that matches the random number I generated earlier."

Anyone know how to do this? Anyone know if this is even possible?

Date: 2006-10-28 04:00 pm (UTC)
From: [identity profile] hantamouse.livejournal.com
*cricket chirps*

Date: 2006-10-28 07:19 pm (UTC)
From: [identity profile] laurie-robey.livejournal.com
Oh well. Guess I'll just go with a case or if statement. Something about this piece of code didn't work, but I have no idea what.

Profile

laurierobey: (Default)
laurierobey

January 2013

S M T W T F S
  1 2 34 5
6 789101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

  • Style: Caturday - Orange Tabby for Heads Up by momijizuakmori

Expand Cut Tags

No cut tags
Page generated Jul. 6th, 2025 09:35 pm
Powered by Dreamwidth Studios