PDA

View Full Version : Parsing Random XML Nodes


kaddison
05-01-2007, 07:30 PM
I could use some help in a problem that have.
I have a small database table that has strings of text that I randomly display onto the client w/ each page refresh.


<?php
require ("connection.inc");

//Open database connection
$connection = mysql_connect($HOST,$USERNAME,$PASSWORD) or
die("ERROR! " . mysql_errno() . " " . mysql_error());

//Select database
mysql_select_db($DATABASE,$connection) or
die("ERROR! Could not select db " . mysql_errno(). mysql_error());

//Run the query through the connection
$query = "SELECT item_txt ";
$query .= "FROM items ORDER BY RAND() LIMIT 1";
$result = mysql_query($query,$connection);

echo "<div class=\"fact\" style=\"padding:0 0 0 0\">";
echo "<h3>FACT</h3>";
//Until there are no rows in the result set, fetch a row into the $row array
while($row = mysql_fetch_row($result))
{
foreach($row as $data)
{
echo "<p>{$data}</p>";
}
}
echo "</div>";
echo "<ul class=\"linklist facta\">";
echo "<li><a href=\"#\">More NASA facts...</a></li>";
echo "</ul>";
?>


what I want to do is eliminate the database table and place the data into a xml file and randomly select the data from the xml datasheet.

Is there a way w/ PHP to randomly select and display data from an xml datasheet?