Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Stronnicowanie newsów
Forum PHP.pl > Forum > Przedszkole
kezman
Cześć, mam problem ze stronnicowaniem newsów, z którym nie mogę się uporać. Problem polega na tym, że wyrzuca mi błąd :

  1. <?php
  2. Something is wrong in your syntax obok 'index' w linii 1
  3. ?>


Cały skrypt wygląda tak :
  1. <?php
  2. $link = mysql_connect('******,'*****','*****');
  3. mysql_select_db('*******',$link);
  4.  
  5. $count=10;
  6. $count = strip_tags($count);
  7. $count = htmlspecialchars($count);
  8. $count = addslashes($count);
  9. $offset=0;
  10. $offset = strip_tags($offset);
  11. $offset = htmlspecialchars($offset);
  12. $offset = addslashes($offset);
  13. echo 'Strona:';
  14.  
  15. if(isset($_GET['count']))$count = $_GET['count'];
  16. if(isset($_GET['offset']))$offset = $count*$_GET['offset']; //numer strony
  17.  
  18. $sql = "Select count(*) from index ORDER BY id DESC";
  19. $result = mysql_query($sql, $link) or die(mysql_error());
  20. $r = mysql_fetch_array($result);
  21.  
  22. @$pages = ceil($r[0]/$count);
  23.  
  24. $sql = "Select * from 'index' ORDER BY 'id' DESC Limit '.$count.' offset '.$offset.';";
  25. $result = mysql_query($sql,$link) or die(mysql_error());
  26.  
  27. for($i=0;$i<$pages;$i++){
  28. if($i*$count==$offset){
  29. echo ' '.$i.' ';
  30. }
  31. else
  32. {
  33. echo '<a href="index.php?count='.$count.'&offset='.$i.'"> '.$i.' </a>';
  34. }
  35. }
  36. while(($row=mysql_fetch_array($result))!=NULL){
  37. echo '<h2>' . $row['tytul'] . '</h2><br>';
  38. echo '' . $row['tresc'] . '<br><br>';
  39. echo '<div class="autor">Autor: ' . $row['autor'] . ' ';
  40. echo 'Data: ' . $row['data'] . '</div><br>;
  41. }
  42. ?>


Tabela index w MySQL wygląda tak :
  1. <?php
  2. -- Struktura tabeli dla  `index`
  3. --
  4.  
  5. CREATE TABLE `index` (
  6.   `id` int(11) NOT NULL AUTO_INCREMENT,
  7.   `tytul` text NOT NULL,
  8.   `autor` varchar(100) NOT NULL DEFAULT '',
  9.   `data` varchar(100) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT '',
  10.   `tresc` text NOT NULL,
  11.   PRIMARY KEY (`id`)
  12. ) ENGINE=MyISAM  DEFAULT CHARSET=latin2 AUTO_INCREMENT=6 ;
  13. ?>


Wersje oprogramowania :
  1. <?php
  2. php 5.2.6
  3. sql 5.1.28-rc-log
  4. ?>


Bardzo proszę o pomoc, pozdrawiam.
wookieb
Kod
$sql = "Select count(*) from 'index' ORDER BY id DESC";
Spawnm
$link = mysql_connect('******,'*****','*****');
nie domkniete '

$sql = "Select * from 'index' ORDER BY 'id' DESC Limit '.$count.' offset '.$offset.';";
dwa razy ';'

'.$count.'

powinno być :
'".$count."' to samo z offset.
kezman
Podmieniłem i teraz :
  1. <?php
  2. Strona:Something is wrong in your syntax obok ''index' ORDER BY id DESC' w linii 1
  3. ?>
wookieb
A wklej teraz cały kod.
kezman
Teraz kod wygląda tak :
  1. <?php
  2. $link = mysql_connect('localhost','saddsa','asdsda');
  3. mysql_select_db('asdasdas',$link);
  4.  
  5. $count=10;
  6. $count = strip_tags($count);
  7. $count = htmlspecialchars($count);
  8. $count = addslashes($count);
  9. $offset=0;
  10. $offset = strip_tags($offset);
  11. $offset = htmlspecialchars($offset);
  12. $offset = addslashes($offset);
  13. echo 'Strona:';
  14.  
  15. if(isset($_GET['count']))$count = $_GET['count'];
  16. if(isset($_GET['offset']))$offset = $count*$_GET['offset']; //numer strony
  17.  
  18. $sql = "Select count(*) from 'index' ORDER BY 'id' DESC";
  19. $result = mysql_query($sql, $link) or die(mysql_error());
  20. $r = mysql_fetch_array($result);
  21.  
  22. @$pages = ceil($r[0]/$count);
  23.  
  24. $sql = "Select * from 'index' ORDER BY 'id' DESC Limit '".$count."' offset '".$offset."'";
  25. $result = mysql_query($sql,$link) or die(mysql_error());
  26.  
  27. for($i=0;$i<$pages;$i++){
  28. if($i*$count==$offset){
  29. echo ' '.$i.' ';
  30. }
  31. else
  32. {
  33. echo '<a href="index.php?count='.$count.'&offset='.$i.'"> '.$i.' </a>';
  34. }
  35. }
  36. while(($row=mysql_fetch_array($result))!=NULL){
  37. echo '<h2>' . $row['tytul'] . '</h2><br>';
  38. echo '' . $row['tresc'] . '<br><br>';
  39. echo '<div class="autor">Autor: ' . $row['autor'] . ' ';
  40. echo 'Data: ' . $row['data'] . '</div><br>';
  41. }
  42. ?>


I wywala taki błąd :

Kod
  Strona:Something is wrong in your syntax obok ''index' ORDER BY 'id' DESC' w linii 1


Proszę o pomoc.
nospor
nie: Select * from 'index'
a: Select * from index

nazwa tabeli to nie tekst winksmiley.jpg
ewentualnie jak juz chcesz ciapkow to uzyj tych:
Select * from `index`

ps: analogicznie pozmieniaj do nazw kolumn
kezman
Teraz jest tak :

  1. <?php
  2. $link = mysql_connect('localhost','asd','asdas');
  3. mysql_select_db('asdasddsa',$link);
  4.  
  5. $count=10;
  6. $count = strip_tags($count);
  7. $count = htmlspecialchars($count);
  8. $count = addslashes($count);
  9. $offset=0;
  10. $offset = strip_tags($offset);
  11. $offset = htmlspecialchars($offset);
  12. $offset = addslashes($offset);
  13. echo 'Strona:';
  14.  
  15. if(isset($_GET['count']))$count = $_GET['count'];
  16. if(isset($_GET['offset']))$offset = $count*$_GET['offset']; //numer strony
  17.  
  18. $sql = "Select count(*) from index ORDER BY id DESC";
  19. $result = mysql_query($sql, $link) or die(mysql_error());
  20. $r = mysql_fetch_array($result);
  21.  
  22. @$pages = ceil($r[0]/$count);
  23.  
  24. $sql = "Select * from index ORDER BY id DESC Limit '".$count."' offset '".$offset."'";
  25. $result = mysql_query($sql,$link) or die(mysql_error());
  26.  
  27. for($i=0;$i<$pages;$i++){
  28. if($i*$count==$offset){
  29. echo ' '.$i.' ';
  30. }
  31. else
  32. {
  33. echo '<a href="index.php?count='.$count.'&offset='.$i.'"> '.$i.' </a>';
  34. }
  35. }
  36. while(($row=mysql_fetch_array($result))!=NULL){
  37. echo '<h2>' . $row['tytul'] . '</h2><br>';
  38. echo '' . $row['tresc'] . '<br><br>';
  39. echo '<div class="autor">Autor: ' . $row['autor'] . ' ';
  40. echo 'Data: ' . $row['data'] . '</div><br>';
  41. }
  42. ?>


I błąd :
Kod
  Strona:Something is wrong in your syntax obok 'index ORDER BY id DESC' w linii 1
nospor
index jest slowem zastrzezonym:
http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html

musisz wiec uzyc ciapkow, o ktorych pisalem
`index`
kezman
Teraz jest tak :

  1. <?php
  2. $count=10;
  3. $count = strip_tags($count);
  4. $count = htmlspecialchars($count);
  5. $count = addslashes($count);
  6. $offset=0;
  7. $offset = strip_tags($offset);
  8. $offset = htmlspecialchars($offset);
  9. $offset = addslashes($offset);
  10. echo 'Strona:';
  11.  
  12. if(isset($_GET['count']))$count = $_GET['count'];
  13. if(isset($_GET['offset']))$offset = $count*$_GET['offset']; //numer strony
  14.  
  15. $sql = "Select count(*) from `index` ORDER BY `id` DESC";
  16. $result = mysql_query($sql, $link) or die(mysql_error());
  17. $r = mysql_fetch_array($result);
  18.  
  19. @$pages = ceil($r[0]/$count);
  20.  
  21. $sql = "Select * from `index` ORDER BY `id` DESC Limit '".$count."' offset '".$offset."'";
  22. $result = mysql_query($sql,$link) or die(mysql_error());
  23.  
  24. for($i=0;$i<$pages;$i++){
  25. if($i*$count==$offset){
  26. echo ' '.$i.' ';
  27. }
  28. else
  29. {
  30. echo '<a href="index.php?count='.$count.'&offset='.$i.'"> '.$i.' </a>';
  31. }
  32. }
  33. while(($row=mysql_fetch_array($result))!=NULL){
  34. echo '<h2>' . $row['tytul'] . '</h2><br>';
  35. echo '' . $row['tresc'] . '<br><br>';
  36. echo '<div class="autor">Autor: ' . $row['autor'] . ' ';
  37. echo 'Data: ' . $row['data'] . '</div><br>';
  38. }
  39. ?>


I wyskakuje :
Kod
  Strona:Something is wrong in your syntax obok ''10' offset '0'' w linii 1
Proszę o pomoc :-/
nospor
w limit podaje sie liczby a nie teksty
nie : limit '1'
a: limit 1

ps: bedziesz tak latal z kazda pierdulą? Zobacz w manualu jak wyglada skladnia zapytania
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.