Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Błąd w zapytaniu do bazy
slawekxx
post 8.02.2014, 07:18:22
Post #1





Grupa: Zarejestrowani
Postów: 189
Pomógł: 2
Dołączył: 28.08.2010

Ostrzeżenie: (0%)
-----


Witam,

Mam taki skrypt do sortowania tabeli
  1. <?php
  2.  
  3. $per_page = 9;
  4.  
  5. if($_GET)
  6. {
  7. $page=$_GET['page'];
  8. }
  9.  
  10. switch($_GET['c']) {
  11. case "1":
  12. $col = "person_name";//
  13. break;
  14. case "2":
  15. $col = "person_surname";//
  16. break;
  17. case "3":
  18. $col = "person_birthdate";//
  19. break;
  20. case "4":
  21. $col = "person_department";//
  22. break;
  23. default:
  24. $col = "person_id";//
  25. }
  26.  
  27. if($_GET['d'] == "1") {
  28. $dir = "DESC";
  29. }
  30. else {
  31. $dir = "ASC";
  32. }
  33.  
  34. if(!$link = mysql_connect("", "", "")) {
  35. echo "Cannot connect to db server";
  36. }
  37. elseif(!mysql_select_db("")) {
  38. echo "Cannot select database";
  39. }
  40. else {
  41. $start = ($page-1)*$per_page;
  42. if(!$rs = mysql_query("SELECT * FROM my_table ORDER BY person_id ")) {
  43. echo "Cannot parse query";
  44. }
  45. elseif(mysql_num_rows($rs) == 0) {
  46. echo "Brak danych";
  47. }
  48. else {
  49. echo "<table id=\"sortedtable\" class=\"bordered\" cellspacing=\"0\">\n";
  50. echo "<thead>\n<tr>";
  51. echo "<th class='ajax'>Record ID</th>";
  52. echo "<th class='ajax'><font>First Name</font></th>";
  53. echo "<th class='ajax'>Last Name</th>";
  54. echo "<th class='ajax'>Birthday</th>";
  55. echo "<th class='ajax'>Department</th>";
  56. echo "</tr>\n</thead>\n";
  57. while($row = mysql_fetch_array($rs)) {
  58. echo "<tr class='edit_tr'><td>$row[person_id]</td><td>$row[person_name]</td><td>$row[person_surname]</td>
  59. <td class='label'>$row[person_birthdate]</td><td>$row[person_department]</td></tr>\n";
  60. }
  61. echo "</table><br />\n";
  62. }
  63. }
  64. ?>


chce zrobić do niego paginacje ale wyskakuje mi błąd jeżeli dopiszę do zapytania dwie zmienne limit $start,$per_page

czyli błąd jest w tak napisanym zapytaniu
  1.  
  2. if(!$rs = mysql_query("SELECT * FROM my_table ORDER BY person_id limit $start,$per_page "))
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.06.2025 - 13:21