<?php
include "config.php";


if ($author) {
    $AuthorQuotes = mysql_query("SELECT quote,author FROM quotes WHERE author = '" . $author . "'", $con);
    while ($myrow = mysql_fetch_array($AuthorQuotes)) {
        $quote = $myrow[0];
        $quote = ereg_replace("(\r\n|\n|\r)", "", $quote);
        echo "<p class=\"quote\">" . $quote . "<i>-- " . $myrow[1] . "</i></p>";
    } 
} else {
    $getNoOfQuotesQuery = mysql_query("select count(*) from quotes", $con);
    $no_of_quotes = mysql_result($getNoOfQuotesQuery, 0);
    while (($row[0] == "") && ($i < 3)) {
        $i++;
        $id = rand(0, $no_of_quotes);
        $getQuoteQuery = mysql_query("SELECT quote,author FROM quotes WHERE id = " . $id, $con);
        $row = mysql_fetch_row($getQuoteQuery);
        if ($row[0]) {
            if ($format == "xml") {
                echo '<?xml version="1.0" encoding="iso-8859-1"?><QuotesList><Quote><Text><?=$row[0]?></Text><Author><?=$row[1]?></Author></Quote></QuotesList>';
            } elseif ($format == "js") {
                $quote = $row[0] . "--" . $row[1];
                $quote = htmlentities($quote);
                $quote = htmlspecialchars($quote);
                $quote = nl2br($quote);
                $quote = ereg_replace("(\r\n|\n|\r)", "", $quote);

                ?>
                document.write("<?=$quote?>");

<?php

            } else {
                $quote = $row[0];
                $quote = ereg_replace("(\r\n|\n|\r)", "", $quote);
                // $quote= nl2br($quote);
                echo "<p class=\"quote\">" . $quote . "<i>-- " . $row[1] . "</i></p>";
            }
        }
    }
}

mysql_close($con);

?>
