2017-12-31 152 views
-1

Geschieht dies nicht eine seltsames ist, ich habe meine MySQL-Abfragen Fügt nur um zu zeigen, führt "WHERE domain_available = 'Y' und domain_category! = 'N/A' und domain_crawler_id = '0'" wenn Ich gehe manuell zu PHPMyAdmin und mache einen SQL-Abfrage-Test bringt es die richtigen Ergebnisse zurück() aber wenn ich das Skript ausführen zählen die Zeilen: echo $ total_results; bringt alle 1300+ Ergebnisse zurück, obwohl ich manuell in der phpmyadmin Query-Tabelle testen, bringt es die Ergebnisse perfekt zurück.Paginierung/mysql Abfrage

<?php 

include('includes/sessions.php'); 
include('includes/db_connection.php'); 
include('includes/functions.php'); 
include('includes/header.php'); 
include('includes/navbar-logged.php'); 

?> 

<?php 

$crawlId = isset($_GET['urlId']) ? $_GET['urlId'] : ''; 

?> 

<?php 

if (!isset($_GET['page'])) { 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

$userInfo = get_logged_in_users_details($member); 
$canEdit  = false; 

if ($userInfo['user_class'] === 'Site Administrator') { 
    $canEdit = true; 
} 

$sort  = isset($_GET['sort']) ? $_GET['sort'] : 'domain_id'; 
$max_results = 500; 
$from  = ($page * $max_results) - $max_results; 

if (isset($crawlId)) { 

    $rows = DB::getInstance()->select(" 
     SELECT * 
     FROM `domains` 
     WHERE `domain_available`='Y' AND `domain_crawler_id`='{$crawlId}' 
     ORDER BY `{$sort}` DESC 
     LIMIT :from, :max_results", 
    [ 
     'from' => [ 
      'type' => PDO::PARAM_INT, 
      'value' => $from 
     ], 
     'max_results' => [ 
      'type' => PDO::PARAM_INT, 
      'value' => $max_results 
     ] 
    ]); 

} else { 

    $rows = DB::getInstance()->select(" 
     SELECT * 
     FROM `domains` 
     WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0' 
     ORDER BY `{$sort}` DESC 
     LIMIT :from, :max_results", 
    [ 
     'from' => [ 
      'type' => PDO::PARAM_INT, 
      'value' => $from 
     ], 
     'max_results' => [ 
      'type' => PDO::PARAM_INT, 
      'value' => $max_results 
     ] 
    ]); 

} 

if (isset($crawlId)) { 
    $total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE`domain_crawler_id`='{$crawlId}'"); 
} else { 
    $total_results = DB::getInstance()->selectValue("SELECT count(*) FROM `domains` WHERE `domain_available`='Y' AND `domain_category`!='N/A' AND `domain_crawler_id`='0'"); 
} 

echo $total_results; 

if (count($rows) < 1) { 
    stderr('Sorry, <b>no</b> domains to show you yet!'); 
} 

$backLinksData = getBackLinksByDomains($rows); 
$isPremiumUser = (int)$user['paid_fees'] === 1; 

?> 

<div class="panel panel-primary"> 
     <div class="panel-heading">Search for expired domains quickly.</div> 
     <div class="panel-body"> 
      <form action="results.php" method="get" class="form-horizontal container-fluid" role="form"> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Domain Contains:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" name="keywords" class="form-control" size="40" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label for="" class="control-label">Anchor Contains:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="text" name="anchor" class="form-control" size="40" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">DA:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="number" min="0" max="100" name="da" value="0" class="form-control" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">PA:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="number" min="0" max="100" name="pa" value="0" class="form-control" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">TF:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="number" min="0" max="100" name="tf" value="0" class="form-control" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">CF:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="number" min="0" max="100" name="cf" value="0" class="form-control" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label">Domains Born After:</label> 
        </div> 
        <div class="col-sm-6"> 
         <input type="number" min="1990" max="2016" name="age" value="1999" class="form-control" /> 
        </div> 
       </div> 

       <div class="row form-group"> 
        <div class="col-sm-6 text-right"> 
         <label class="control-label" style="display: inline-block;">&nbsp;</label> 
        </div> 
        <div class="col-sm-6 text-right"> 
         <button type="submit" name="submit" class="btn btn-default">Search</button> 
        </div> 
       </div> 

      </form> 
     </div> 
     <div class="panel-footer">Search for domains using <b>your</b> criteria.</div> 
</div> 

<div class="panel panel-primary"> 
    <div class="panel-heading">Browse Domains - <b>*<font color="orange">spam</font>*</b> = Potential spam domain! <b>*<font color="red">HP</font>*</b> = A homepage link points to this domain!</div> 
    <div class="panel-body"> 
     <table class="table table-striped table-condensed table-hover table-responsive"> 
      <thead> 
       <tr> 
        <th>Alexa</th> 
        <th>Domain/Category</th> 
        <th><a href="expired-domains.php?sort=domain_moz_da">DA</a></th> 
        <th><a href="expired-domains.php?sort=domain_moz_pa">PA</a></th> 
        <th><a href="expired-domains.php?sort=domain_tf">TF</a></th> 
        <th><a href="expired-domains.php?sort=domain_cf">CF</a></th> 
        <th><a href="expired-domains.php?sort=domain_indexed">Indexed</a></th> 
        <th><a href="expired-domains.php?sort=domain_age">Age</a></th> 
        <th>BL</th> 
        <th><a href="expired-domains.php?sort=domain_ref_domains">RD</a></th> 
        <th>Found</th> 
        <?php if ($canEdit): ?> 
        <th>Actions</th> 
        <?php endif; ?> 
       </tr> 
      </thead> 
      <tbody> 
       <?php foreach ($rows as $row) { ?> 
        <?php 
         //$bgcolor = ($bgcolor == '#eeeeee'? '#ffffff': '#eeeeee'); 
         $domID  = $row['domain_id']; 
         $domNM  = $row['domain_name']; 
         $domDT  = $row['domain_date']; 
         $domAL  = $row['domain_alexa_rank']; 
         $domDA  = $row['domain_moz_da']; 
         $domPA  = $row['domain_moz_pa']; 
         $domTF  = $row['domain_tf']; 
         $domCF  = $row['domain_cf']; 
         $domRD  = $row['domain_ref_domains']; 
         $domDC  = $row['domain_age']; 
         $domIN  = $row['domain_indexed']; 
         $domHP  = $row['domain_homepage']; 
         $domCT  = $row['domain_category']; 

         $time_1 = date('Y-m-d H:i:s', strtotime($domDT . ' +1 hour')); 
         $time_2 = date('Y-m-d H:i:s', time()); 

         $string = $domNM; 
         $array  = array("sunglasses","payday","casino","viagra","cashloans","loans","sex","porn","xxx"); 
         $spam  = 0; 

         foreach ($array as $token) { 
          if (stristr($string, $token) !== FALSE) { 
           $spam = 1; 
          } 
         } 
        ?> 
        <tr> 
         <td><?php echo htmlspecialchars($domAL); ?></td> 
         <td> 
          <?php 
          $domainUrl = $isPremiumUser ? $domNM : getObscuredUrl($domNM); 
          $domainCat = ($domCT == "N/A") ? "<font color=\"red\"><b>Uncategorized</b></font>" : "<font color=\"green\"><b>{$domCT}</b></font>"; 
          ?> 
          <a href="domain-details.php?id=<?php echo $domID; ?>"><b><?php echo htmlspecialchars($domainUrl); ?></b></a> <b>in</b> <?php echo $domainCat; ?> 
          <?php if ($time_2 <= $time_1) { ?> 
           <b>(<font color="red">NEW</font>)</b> 
          <?php } ?> 
          <?php if ($spam) { ?> 
           <b>*<font color="orange">spam</font>*</b> 
          <?php } ?> 
          <?php if ($domHP) { ?> 
           <b>*<font color="red">HP</font>*</b> 
          <?php } ?> 
         </td> 
         <td> 
         <?php echo $domDA; ?> 
         </td> 
         <td> 
         <?php echo $domPA; ?> 
         </td> 
         <td> 
         <?php echo $domTF; ?> 
         </td> 
         <td> 
         <?php echo $domCF; ?> 
         </td> 
         <td> 
         G=<?php if ($domIN == 0) { echo "<font color=\"red\"><b>No</b></font>"; } else { echo "<font color=\"green\"><b>Yes</b></font>"; } ?> 
         </td> 
         <td> 
         <?php if ($domDC == "????") { echo "<b><font color=\"red\">????</font></b>"; } else { echo $domDC; } ?> 
         </td> 
         <td> 
         <?= isset($backLinksData[$domNM]) ? $backLinksData[$domNM] : 0; ?> 
         </td> 
         <td> 
         <?php if (empty($domRD)) { echo "-"; } else { echo $domRD; } ?> 
         </td> 
         <td> 
         <b><?php echo date("m.d.y", strtotime($domDT)); ?></b> 
         </td> 
         <?php if ($canEdit): ?> 
          <td>(<a href="master-edit-domain.php?id=<?php echo $domID ?>">e</a>)-(<a href="master-delete-domain.php?id=<?php echo $domID ?>" onclick="return confirm('Are you sure you want to delete this domain?');">d</a>)</td> 
         <?php endif; ?> 
        </tr> 
       <?php } ?> 
      </tbody> 
     </table> 
    </div> 
    <div class="panel-footer text-center"> 
     <?php pagination($page, $total_results, $max_results) ?> 
    </div> 
</div> 

<?php 

include('includes/footer.php'); 

Ich kann nicht sehen, warum die Abfrage in phpMyAdmin funktioniert, aber nicht, wenn ich das Skript ausführen, gibt es etwas, das ich übersehen haben, und Hilfe würde geschätzt.

+0

vielleicht, weil '$ crawlID' will ist _always_ gesetzt ?? – Jeff

+0

fügen Sie einfach ein 'echo isset ($ crawlId);' nach $ crawlId = isset ($ _ GET ['urlId']) .... 'hinzu und überprüfen Sie es selbst. – Jeff

+0

möchten Sie vielleicht [empty] (http://php.net/manual/en/function.empty.php) anstelle von isset verwenden – Jeff

Antwort

2

$crawlId ist immer hier eingestellt, weil Sie es ganz oben setzen. Sie setzen es jedoch auf '', was immer noch als gesetzt gilt.

So könnten Sie verwenden if(!empty($crawlId)) {...} statt isset()