browse.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. header('Location: http://php-gtk.audean.com');
  3. $query = "SELECT DISTINCT(LEFT(sect, 1)) AS first FROM note ORDER BY first";
  4. $result = mysql_query($query) or die(mysql_error());
  5. $used = array();
  6. $fl = '';
  7. if (mysql_num_rows($result) > 0) {
  8. while ($row = mysql_fetch_array($result)) {
  9. if (!$fl) {
  10. $fl = $row['first'];
  11. }
  12. $used[ $row['first'] ] = true;
  13. }
  14. }
  15. $links = array();
  16. for($i=ord('a'); $i<=ord('z'); $i++ ) {
  17. $l = chr($i);
  18. if (isset($used[$l])) {
  19. $links[] = make_link($PHP_SELF.'?let='.$l, '<b>'.$l.'</b>' );
  20. } else {
  21. $links[] = $l;
  22. }
  23. }
  24. $jumpbar = '<table border="0" cellpadding="4" cellspacing="0" width="100%">' .
  25. '<tr bgcolor="#d0d0d0" valign="top">' .
  26. '<td align="right" colspan="2"><small>Jump to: ' .
  27. join (' <font color="#999999">|</font> ', $links ) .
  28. '<br /></small></td>' .
  29. "</tr>\n" .
  30. "</table><br />\n\n";
  31. echo $jumpbar;
  32. if (!$let) {
  33. $let = $fl;
  34. }
  35. echo '<table border="0" cellpadding="4" cellspacing="0" width="100%">';
  36. $query = "SELECT *, UNIX_TIMESTAMP(ts) AS xwhen, IF(votes=0, 10, rating/votes) AS rate FROM note " .
  37. "WHERE sect LIKE '$let%' ORDER BY sect, rate DESC, id";
  38. $result = mysql_query($query) or die(mysql_error());
  39. $numrows = mysql_num_rows($result);
  40. if ($numrows > 0) {
  41. $last = '';
  42. while ($row = mysql_fetch_array($result)) {
  43. if ($row['sect'] != $last) {
  44. makeTitle($row['sect']);
  45. $last = $row['sect'];
  46. }
  47. makeEntry($row);
  48. }
  49. } else if (!$fl) {
  50. echo '<tr><td colspan="2">No entries for any section</b>.<br /></td></tr>';
  51. } else {
  52. echo '<tr><td colspan="2">No entries for <b>'.$let.'</b>.<br /></td></tr>';
  53. }
  54. echo '</table>';
  55. if ($numrows > 10) {
  56. echo $jumpbar;
  57. }
  58. ?>