Quote database webapp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tag.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?PHP
  2. require_once('inc/database.php');
  3. if (isset($_GET['tag'])) {
  4. define('TAG', $_GET['tag']);
  5. } else {
  6. header('Location: ' . BASE . 'latest');
  7. exit;
  8. }
  9. define('TITLE', 'Browse quotes tagged ' . htmlentities(TAG, ENT_QUOTES, 'UTF-8'));
  10. require_once('inc/header.php');
  11. require_once('inc/tags.php');
  12. $offset = 0;
  13. if (isset($_GET['o']) && ctype_digit($_GET['o'])) {
  14. $offset = $_GET['o'];
  15. }
  16. $quotes = array();
  17. $sql = 'SELECT DISTINCT(quote_id) FROM tags WHERE tag_text = \'' . m(TAG) . '\'';
  18. $res = mysql_query($sql);
  19. while ($row = mysql_fetch_assoc($res)) {
  20. $quotes[] = $row['quote_id'];
  21. }
  22. $where = 'WHERE quote_id IN (' . implode(', ', $quotes) . ')';
  23. $sql = 'SELECT COUNT(*) FROM quotes ' . $where;
  24. $res = mysql_query($sql);
  25. $row = mysql_fetch_array($res);
  26. define('QUOTES', $row[0]);
  27. $sql = 'SELECT quote_id, quote_quote, quote_rating FROM quotes ' . $where . ' ORDER BY quote_id LIMIT '.$offset.',25';
  28. $res = mysql_query($sql)
  29. ?>
  30. <div>
  31. <h2>Browse quotes tagged <?PHP echo htmlentities(TAG, ENT_QUOTES, 'UTF-8'); ?></h2>
  32. <?PHP
  33. echo '<div class="nav">';
  34. if ($offset > 0) {
  35. echo '<a href="browse?o='.($offset-25).'">&lt;&lt; Previous</a> |';
  36. }
  37. if ($offset + 25 > QUOTES) { $max = QUOTES; } else { $max = $offset + 25; }
  38. echo ' Viewing quotes '.(1+$offset).' to '.$max.' of '.QUOTES.'.';
  39. if ($max < QUOTES) {
  40. echo ' | <a href="browse?o='.$max.'">Next &gt;&gt;</a>';
  41. }
  42. echo '</div>';
  43. $i = 0;
  44. while ($row = mysql_fetch_array($res)) {
  45. $i = 1 - $i;
  46. if ($i == 1) { $e = 'even'; } else { $e = 'odd'; }
  47. ?>
  48. <div class="quote <?PHP echo $e; ?>">
  49. <?PHP
  50. if (isset($_SESSION['uid'])) {
  51. doRate($row['quote_id']);
  52. }
  53. ?>
  54. <p>
  55. Quote <a href="<?PHP echo BASE; ?>browse?q=<?PHP echo $row['quote_id']; ?>">#<?PHP echo $row['quote_id']; ?></a>.
  56. Rating <?PHP echo round($row['quote_rating'],2); ?>.
  57. <?PHP
  58. if (!isset($_SESSION['uid'])) {
  59. echo ' <a href="'.BASE.'login">Login to rate</a>.';
  60. }
  61. ?>
  62. </p>
  63. <?PHP showTags($row['quote_id']); ?>
  64. <div class="quotebody">
  65. <?PHP echo nl2br(htmlentities($row['quote_quote'], ENT_QUOTES, 'UTF-8')); ?>
  66. </div>
  67. </div>
  68. <?PHP
  69. }
  70. echo '<div class="nav">';
  71. if ($offset > 0) {
  72. echo '<a href="browse?o='.($offset-25).'">&lt;&lt; Previous</a> |';
  73. }
  74. if ($offset + 25 > QUOTES) { $max = QUOTES; } else { $max = $offset + 25; }
  75. echo ' Viewing quotes '.(1+$offset).' to '.$max.' of '.QUOTES.'.';
  76. if ($max < QUOTES) {
  77. echo ' | <a href="browse?o='.$max.'">Next &gt;&gt;</a>';
  78. }
  79. echo '</div>';
  80. ?>
  81. </div>
  82. <?PHP
  83. require_once('inc/footer.php');
  84. ?>