Changeset 35151


Ignore:
Timestamp:
Mar 18, 2008, 4:41:34 PM (12 years ago)
Author:
jmpp@…
Message:

As written, every query built by the search menu selection has a "WHERE 1 AND <other criteria>" in it, which is absolutely unnecessary.
Get rid of it and also rename $query variable to $criteria, to better reflect its intent as the query is being built.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/ports.php

    r35135 r35151  
    8181    if ($by && ($substr || $by == "all")) {
    8282        $fields = "name, path, version, description";
    83         $query = "1";
    8483        $tables = "$portsdb_name.portfiles p";
    8584        if ($by == "name") {
    86             $query .= " AND p.name LIKE '%" . mysql_real_escape_string($substr) . "%'";
     85            $criteria = "p.name LIKE '%" . mysql_real_escape_string($substr) . "%'";
    8786        }
    8887        if ($by == "category") {
    8988            $tables .= ", $portsdb_name.categories c";
    90             $query .= " AND c.portfile=p.name AND c.category='" . mysql_real_escape_string($substr) . "'";
     89            $criteria = "c.portfile = p.name AND c.category = '" . mysql_real_escape_string($substr) . "'";
    9190        }
    9291        if ($by == "maintainer") {
    9392            $tables .= ", $portsdb_name.maintainers m";
    94             $query .= " AND m.portfile=p.name AND m.maintainer LIKE '%" . mysql_real_escape_string($substr) . "%'";
     93            $criteria = "m.portfile = p.name AND m.maintainer LIKE '%" . mysql_real_escape_string($substr) . "%'";
    9594        }
    9695        if ($by == "library") {
    97             $query .= " AND p.name='" . mysql_real_escape_string($substr) . "'";
     96            $criteria = "p.name = '" . mysql_real_escape_string($substr) . "'";
    9897        }
    9998        if ($by == "variant") {
    10099            $tables .= ", $portsdb_name.variants v";
    101             $query .= " AND v.portfile=p.name AND v.variant='" . mysql_real_escape_string($substr) . "'";
     100            $criteria = "v.portfile = p.name AND v.variant = '" . mysql_real_escape_string($substr) . "'";
    102101        }
    103102        if ($by == "platform") {
    104103            $tables .= ", $portsdb_name.platforms pl";
    105             $query .= " AND pl.portfile=p.name AND pl.platform ='" . mysql_real_escape_string($substr) . "'";
    106         }
    107         $query = "SELECT DISTINCT $fields FROM $tables WHERE $query ORDER BY name";
     104            $criteria = "pl.portfile = p.name AND pl.platform = '" . mysql_real_escape_string($substr) . "'";
     105        }
     106        $query = "SELECT DISTINCT $fields FROM $tables WHERE $criteria ORDER BY name";
    108107        $result = mysql_query($query);
    109108        if ($result) {
Note: See TracChangeset for help on using the changeset viewer.