Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MYSQL] Problem ze stronnicowaniem
Forum PHP.pl > Forum > Przedszkole
bemol
Napisałem własną wyszukiwarkę. I podzieliłem na wyszukiwanie proste, zaawansowane itp.
Tutaj kod zaawansowanego:
  1. <?php
  2. case 'advanced'<span style="color: #007700": {
  3.      if ($_POST['City'] != "") {$City = "= '".$_POST['City']."'";} else {$City = "LIKE '%%'";}
  4.      if ($_POST['AgeMin'] != "-") {$AgeMin = SubtractionTime(date("Y-m-d"),substr($_POST['AgeMin'],0,2));} else {$AgeMin = '2099-12-31';}
  5.      if ($_POST['AgeMax'] != "-") {$AgeMax = SubtractionTime(date("Y-m-d"),substr($_POST['AgeMax'],0,2));} else {$AgeMax = '0000-00-00';}
  6.      if ($_POST['Sex'] == "men") {$Sex = "='M'";} elseif ($_POST['Sex'] == "women") {$Sex = "='F'";} else {$Sex = "LIKE '%%'";}
  7.      if ($_POST['Sort'] == "ostatnia aktywność") { $Sort = 'UserLastActive'; } elseif ($_POST['Sort'] == "najnowsze zdjęcie") {$Sort = 'UserLastPhoto';} elseif ($_POST['Sort'] == "po średniej") {$Sort = 'UserAverageMark';} elseif ($_POST['Sort'] == "alfabetycznie") {$Sort = 'UserNick';}
  8.      if ($_POST['MinHeight'] != "-") { $MinHeight = substr($_POST['MinHeight'],0,3);} else {$MinHeight = 0;}
  9.      if ($_POST['MaxHeight'] != "-") { $MaxHeight = substr($_POST['MaxHeight'],0,3);} else {$MaxHeight = 230;}
  10.      if ($_POST['HairColor'] != "dowolny") {$HairColor = "= '".$_POST['HairColor']."'";} else {$HairColor = "LIKE '%%'";}
  11.      if ($_POST['HairLength'] != "dowolna") {$HairLength = "= '".$_POST['HairLength']."'";} else {$HairLength = "LIKE '%%'";}
  12.      if ($_POST['EyesColor'] != "dowolny") {$EyesColor = "= '".$_POST['EyesColor']."'";} else {$EyesColor = "LIKE '%%'";}
  13.      if ($_POST['Smoke'] != "dowolnie") {$Smoke = "= '".$_POST['Smoke']."'";} else {$Smoke = "LIKE '%%'";}
  14.      if ($_POST['Alcohol'] != "dowolnie") {$Alcohol = "= '".$_POST['Alcohol']."'";} else {$Alcohol = "LIKE '%%'";}
  15.      if ($_POST['Education'] != "dowolne") {$Education = "= '".$_POST['Education']."'";} else {$Education = "LIKE '%%'";}
  16.      if ($_POST['Children'] != "dowolnie") {$Children = "= '".$_POST['Children']."'";} else {$Children = "LIKE '%%'";}
  17.      if ($_POST['GG'] != "GG") {$GG = "LIKE '%%'";} else {$GG = "!= '' AND UserHideGG = 'No'"; }
  18.      if ($_POST['Skype'] != "Skype") {$Skype = "LIKE '%%'";} else {$Skype = "!= '' AND UserHideSkype = 'No'"; }
  19.    $DB = new Engine( DBHOST, DBADMIN, DBPASS, DBNAME );
  20.       if ( $DB->IsConnected ) {
  21.           $DB->Query("SELECT FROM Users WHERE UserGG ".$GG." AND UserSkype ".$Skype." AND UserLocCity ".$City." AND UserBirthDate BETWEEN '$AgeMax' AND '$AgeMin' AND UserSex ".$Sex." AND UserHairColor ".$HairColor." AND UserHairLength ".$HairLength." AND UserEyesColor ".$EyesColor." AND UserSmoke ".$Smoke." AND UserAlcohol ".$Alcohol." AND UserEducation ".$Education." AND UserChildren ".$Children." AND UserHeight BETWEEN '$MinHeight' AND '$MaxHeight' ORDER BY ".$Sort.";");
  22.  $Records = $DB->NRows();
  23.    $Photos = 10;
  24.    if ($Records == 1) {
  25.           while ($Row = $DB->FetchArray()) { HREF("profile.php?id=".$Row['UserID']); }
  26.     } elseif($Records > 1)    {
  27.    
  28.    if ( !isset($_GET['subpage']) ) {
  29.    $_GET['subpage'] = 1;
  30.    }
  31.    
  32.    $subpages = ceil($Records/$Photos);
  33.    
  34.      $Start = ($_GET['subpage']-1)*$Photos;
  35.        
  36.        $Temp = 0;
  37.        
  38.        echo '<div align="center" width="80%"><table><tr>';
  39.          
  40.                    if($_GET['subpage']>1) echo '<td><a href="search.php?method=advanced&subpage='.($_GET['subpage']-1).'">Poprzednia</a></td>';
  41.            if($subpages<=10)
  42.                 {
  43.                 for ($s=1; $s<=$subpages; $s++){
  44.                 if ($s==$_GET['subpage']) echo '<td>'.$s.'</td>';
  45.                 else echo '<td><a href="search.php?method=advanced&subpage='.$s.'">'.$s.'</a></td>';}
  46.                 }  
  47.                 elseif($subpages>10)
  48.                 {
  49.                 if($next>=6 && $_GET['$subpage']<=$subpages-5){
  50.                 $wr=$_GET['subpage']-4;
  51.                 $wz=$_GET['subpage']+5;
  52.                 for ($s=$wr; $s<=$wz; $s++){
  53.                   if ($s==$_GET['subpage']) echo '<td>'.$s.'</td>';
  54.                   else echo '<td><a href="search.php?method=advanced&subpage='.$s.'">'.$s.'</a></td>';
  55.                   }
  56.                   }
  57.                  else if($_GET['subpage']>=$subpages-5){
  58.                  for ($s=$subpages-9; $s<=$subpages; $s++){
  59.                   if ($s==$_GET['subpage']) echo '<td>'.$s.'</td>';
  60.                   else echo '<td><a href="search.php?method=advanced&subpage='.$s.'">'.$s.'</a></td>';
  61.                   }              
  62.                   }
  63.                 else{
  64.                 for ($s=1; $s<=10; $s++){
  65.                 if ($s==$_GET['subpage']) echo '<td>'.$s.'</td>';
  66.                 else echo '<td><a href="search.php?method=advanced&subpage='.$s.'">'.$s.'</a></td>';}
  67.                 }
  68.                 } if($_GET['subpage']<$subpages) echo '<td><a href="search.php?method=advanced&subpage='.($_GET['subpage']+1).'">Następna</a></td>';
  69.        echo "</tr></table></div>";
  70.    
  71.     $DB->Query("SELECT * FROM Users WHERE UserGG ".$GG." AND UserSkype ".$Skype." AND UserLocCity ".$City." AND UserBirthDate BETWEEN '$AgeMax' AND '$AgeMin' AND UserSex ".$Sex." AND UserHairColor ".$HairColor." AND UserHairLength ".$HairLength." AND UserEyesColor ".$EyesColor." AND UserSmoke ".$Smoke." AND UserAlcohol ".$Alcohol." AND UserEducation ".$Education." AND UserChildren ".$Children." AND UserHeight BETWEEN '$MinHeight' AND '$MaxHeight' ORDER BY ".$Sort." LIMIT $Start,$Photos;");
  72.        
  73.         echo '<div align="center" width="80%" style="overflo:hidden;border: 2px #f49410 solid;"><br />';
  74.        
  75.      while ( $Row = $DB->FetchArray() ) {
  76.      if ($Row['UserHideEmail'] == "Yes") { $Row['UserEmail'] = 'Ukryty'; }
  77.      if ($Row['UserHideGG'] == "Yes") { $Row['UserGG'] = 'Ukryty'; }
  78.      if ($Row['UserHideSkype'] == "Yes") { $Row['UserSkype'] = 'Ukryty'; }
  79.        $Temp++;
  80.            echo '<div style="alig:center;overflo:hidden;border: 1px #ff7400 dashed;floa:left;widt:202px;">
  81.        <div width="200"><b>'.$Row['UserNick'].'</b> '.ChooseSex($Row['UserSex']).' <b>'.$Row['UserAverageMark'].'</b></div>';
  82.            echo '<div width="200"><img src="profiles/'.$Row['UserID'].'/photos/mini/'.$Row['UserPhotoDefault'].'.jpg" alt="" /></div>';
  83.            echo '<div width="200">'.Age($Row['UserBirthDate']).' lat</div>';
  84.            echo '<div width="200">'.$Row['UserLocCity'].' ('.$Row['UserLocProvince'].')</div>';
  85.            echo '<div width="200">'.$Row['UserEmail'].'</div>';
  86.            echo '<div width="200">'.$Row['UserGG'].'</div>';
  87.        echo '<div width="200">'.$Row['UserSkype'].'</div>';
  88.            echo '<div width="200">'.Timer($Row['UserLastActive'],'NOW').'</div>
  89.        </div>';
  90.        }
  91.    echo '<br /></div>';
  92.     } else echo 'Nie znaleziono osoby odpowiadającej podanym kryteriom.';
  93.          }
  94.    break;}
  95. ?>


Nie działa, jeśli nacisnę na 2 stronę wyskakuje błąd:
"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/teodor/public_html/konto/engine.class.php on line 85
Nie znaleziono osoby odpowiadającej podanym kryteriom. "

Prosze nie pisać, że może funkcja ta jest zła, bo zawsze i wszedzie chodziła, problem może być z zapytaniem.
Proszę o pomoc
nospor
Cytat
problem może być z zapytaniem.
Czy naprawde wielkim problemem jest zrobienie czegos takiego:
  1. <?php
  2. $sql = ' tu moje skladane zapytanie z wielu zmiennych';
  3.  
  4. //a tu je sobie po utworzeniu wyswietle i przeanalizuje
  5. echo $sql;
  6.  
  7. //tu sie wykona
  8. ......
  9.  
  10. //a tu se walne mysql_error() by zobaczyc jakie byly bledy w zapytaniu
  11. echo 'Bledy to: '.mysql_error();
  12. ?>

?
Wstaw to do swojej struktury i bedzieszz wiedzial gdzie masz blad, a nawet jak sie nie dowiesz to przynajmniej bedziesz blizej rozwiazania
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.