1. Nie chce mi wyświetlać tabeli w przypadku braku hasła
2. Nie wyświetlają się tabele z dir=DESC.
3. Przy wpisywaniu w przeglądarce zmiennych get wszystko ładnie działa
4. Skopiowałem to z innej strony, ale nie było na niej searchname

  1. <?
  2. connect();
  3.  
  4. $wyborbazy = mysql_select_db("baza_matys");
  5.  
  6.  
  7. if (isset($_SESSION['logged']))
  8. $_SESSION['logged'] = filter_var($_SESSION['logged'], FILTER_SANITIZE_STRING);
  9.  
  10. if (isset($_GET['sortby']))
  11. {
  12. $_GET['sortby'] = filter_var($_GET['sortby'], FILTER_SANITIZE_STRING);
  13. $_SESSION['sortby'] = $_GET['sortby'];
  14. }
  15. $sortby = $_SESSION['sortby'];
  16.  
  17. if (isset($_GET['dir']))
  18. {
  19. $_GET['dir'] = filter_var($_GET['dir'], FILTER_SANITIZE_STRING);
  20. $_SESSION['dir'] = $_GET['dir'];
  21. }
  22. $dir = $_SESSION['dir'];
  23.  
  24. if (isset($_GET['page']))
  25. {
  26. $_GET['page'] = filter_var($_GET['page'], FILTER_SANITIZE_STRING);
  27. $_SESSION['page'] = $_GET['page'];
  28. }
  29. $page = $_SESSION['page'];
  30.  
  31. if (isset($_POST['searchname']))
  32. {
  33. $_POST['searchname'] = filter_var($_POST['searchname'], FILTER_SANITIZE_STRING);
  34. $_SESSION['searchname'] = $_POST['searchname'];
  35. }
  36. $searchname = $_SESSION['searchname'];
  37.  
  38. if (isset($_SESSION['searchname']))
  39. {
  40. if (!empty($_SESSION['searchname']))
  41. {
  42.  
  43. $_SESSION['searchname'] = $_POST["searchname"];
  44. $searchname = $_SESSION['searchname'];
  45. $query = "
  46. SELECT * from table_books
  47. WHERE author LIKE '%$searchname%' OR book_name LIKE '%$searchname%'
  48.  
  49. ";
  50. $result = mysql_query($query) or die(mysql_error());
  51. }
  52. if (empty($query))
  53. {
  54. echo "";
  55. }
  56. else
  57. {
  58. $counter = mysql_num_rows($result);
  59. $num_of_pages = ceil($counter/10);
  60. if (isset($_GET['page']))
  61. {
  62. if (!empty($_GET['page']) )
  63. {
  64.  
  65. $_GET['page'] = filter_var($_GET['page'], FILTER_SANITIZE_STRING);
  66.  
  67.  
  68.  
  69. if (($_GET['page'] > $num_of_pages) )
  70. {
  71. echo "Site not exist!";
  72. }
  73.  
  74.  
  75. if ($_GET['page']!=NULL)
  76. if (!is_numeric($_GET['page']))
  77. {
  78. echo "Site not exist!";
  79. }
  80. }
  81.  
  82. }
  83. function sort_first_table()
  84. {
  85. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  86. <th>LP</th>
  87. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  88. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  89. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  90. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  91. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  92. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  93. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  94. </tr>";
  95. }
  96. if ((!empty($_SESSION['sortby'])) && (!empty($_SESSION['dir'])))
  97. {
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  

...



Dalsza część kodu

  1. if ($_SESSION['sortby'] == "book_id")
  2. {
  3. if ($_SESSION['dir'] == "ASC")
  4. {
  5. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  6. <th>LP</th>
  7. <th><a href='searchbooks.php?sortby=book_id&dir=DESC'>ID &and;</a></th>
  8. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  9. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  10. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  11. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  12. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  13. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  14. </tr>";
  15. }
  16.  
  17. else if ($_SESSION['dir'] == "DESC")
  18. {
  19. sort_first_table();
  20. }
  21. }
  22. if ($_SESSION['sortby'] == "book_name")
  23. {
  24. if ($_SESSION['dir'] == "ASC")
  25. {
  26. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  27. <th>LP</th>
  28. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  29. <th><a href='searchbooks.php?sortby=book_name&dir=DESC'>Book Name &and;</a></th>
  30. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  31. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  32. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  33. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  34. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  35. </tr>";
  36. }
  37.  
  38. else if ($_SESSION['dir'] == "DESC")
  39. {
  40. sort_first_table();
  41. }
  42. }
  43.  
  44. if ($_SESSION['sortby'] == "author")
  45. {
  46. if ($_SESSION['dir'] == "ASC")
  47. {
  48.  
  49. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  50. <th>LP</th>
  51. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  52. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  53. <th><a href='searchbooks.php?sortby=author&dir=DESC'>Author &and;</a></th>
  54. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  55. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  56. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  57. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  58. </tr>";
  59. }
  60.  
  61. else if ($_SESSION['dir'] == "DESC")
  62. {
  63. sort_first_table();
  64. }
  65. }
  66.  
  67.  
  68. if ($_SESSION['sortby'] == "publishing_house")
  69. {
  70. if ($_SESSION['dir'] == "ASC")
  71. {
  72. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  73. <th>LP</th>
  74. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  75. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  76. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  77. <th><a href='searchbooks.php?sortby=publishing_house&dir=DESC'>Publishing house &and;</a></th>
  78. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  79. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  80. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  81. </tr>";
  82. }
  83.  
  84. else if ($_SESSION['dir'] == "DESC")
  85. {
  86. sort_first_table();
  87. }
  88. }
  89.  
  90. if ($_SESSION['sortby'] == "year_of_publication")
  91. {
  92. if ($_SESSION['dir'] == "ASC")
  93. {
  94.  
  95. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  96. <th>LP</th>
  97. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  98. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  99. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  100. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  101. <th><a href='searchbooks.php?sortby=year_of_publication&dir=DESC'>Year of publication &and;</a></th>
  102. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  103. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  104. </tr>";
  105. }
  106.  
  107. else if ($_SESSION['dir'] == "DESC")
  108. {
  109. sort_first_table();
  110. }
  111. }
  112.  
  113.  
  114. if ($_SESSION['sortby'] == "binding")
  115. {
  116. if ($_SESSION['dir'] == "ASC")
  117. {
  118.  
  119. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  120. <th>LP</th>
  121. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  122. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  123. <th><a href='searchbooks.php?sortby=author&dir=ASSC'>Author &or;</a></th>
  124. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  125. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  126. <th><a href='searchbooks.php?sortby=binding&dir=DESC'>Binding &and;</a></th>
  127. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th>
  128. </tr>";
  129. }
  130.  
  131. else if ($_SESSION['dir'] == "DESC")
  132. {
  133. sort_first_table();
  134. }
  135. }
  136.  
  137. if ($_SESSION['sortby'] == "availability")
  138. {
  139. if ($_SESSION['dir'] == "ASC")
  140. {
  141.  
  142. echo "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  143. <th>LP</th>
  144. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  145. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  146. <th><a href='searchbooks.php?sortby=author&dir=ASSC'>Author &or;</a></th>
  147. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  148. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  149. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  150. <th><a href='searchbooks.php?sortby=availability&dir=DESC'>Availability &and;</a></th>
  151. </tr>";
  152. }
  153.  
  154. else if ($_SESSION['dir'] == "DESC")
  155. {
  156. sort_first_table();
  157. }
  158. }
  159. }
  160. }
  161.  
  162. }
  163.  
  164. else
  165. {
  166. "<table bgcolor=#EEEEEE border=1 align=center width='920'><tr>
  167. <th>LP</th>
  168. <th><a href='searchbooks.php?sortby=book_id&dir=ASC'>ID &or;</a></th>
  169. <th><a href='searchbooks.php?sortby=book_name&dir=ASC'>Book Name &or;</a></th>
  170. <th><a href='searchbooks.php?sortby=author&dir=ASC'>Author &or;</a></th>
  171. <th><a href='searchbooks.php?sortby=publishing_house&dir=ASC'>Publishing house &or;</a></th>
  172. <th><a href='searchbooks.php?sortby=year_of_publication&dir=ASC'>Year of publication &or;</a></th>
  173. <th><a href='searchbooks.php?sortby=binding&dir=ASC'>Binding &or;</a></th>
  174. <th><a href='searchbooks.php?sortby=availability&dir=ASC'>Availability &or;</a></th></tr>";
  175. }
  176. ?>


Jeszcze taki searchbar na początku

  1. <form name="searchbar" method="post" action="searchbooks.php">
  2. <input name="searchname" type="text" size="30" maxlength="40">
  3. <input type="submit" value="Search book">
  4. </form>