From 1f62f86af5225643f2a7d72c1a050c46ffc37477 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 24 Jun 2004 19:08:35 +0000 Subject: getting closer to printing package search results - also fixed some XHTML stuff --- web/lib/pkgs.inc | 114 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 12 deletions(-) (limited to 'web/lib/pkgs.inc') diff --git a/web/lib/pkgs.inc b/web/lib/pkgs.inc index e26d455d..bd63ee2e 100644 --- a/web/lib/pkgs.inc +++ b/web/lib/pkgs.inc @@ -35,14 +35,18 @@ function pkgLocations() { # display the search form in a boxSoft style # -function pkg_search_page($L="",$C="",$K="",$SB="",$PP="") { +function pkg_search_page($L="",$C="",$K="",$SB="",$O=0,$PP=25) { # L: PackageLocations.ID # C: PackageCategories.ID # K: Keywords # SB: Sort by + # O: Row offset # PP: Per page $locs = pkgLocations(); $cats = pkgCategories(); + $devs = getDevelopers(); + $tus = getTrustedUsers(); + $dbh = db_connect(); print "
\n"; print "\n"; @@ -60,7 +64,7 @@ function pkg_search_page($L="",$C="",$K="",$SB="",$PP="") { print "\n"; print "\n"; print "\n"; print "
\n"; print " ".__("Location"); - print "
\n"; + print "
\n"; print "
\n"; print " ".__("Category"); - print "
\n"; + print "
\n"; print "
\n"; print " ".__("Keywords"); - print "
\n"; + print "
\n"; print " \n"; print "
\n"; print " ".__("Sort by"); - print "
\n"; + print "
\n"; print "
\n"; print " ".__("Per page"); - print "
\n"; + print "
\n"; print "
\n"; + print "\n"; + print " \n"; + print "\n"; + print "\n"; + print "
\n"; + print "
\n"; + + print "
\n"; + print "\n"; + print "\n"; + print " \n"; + print " \n"; print "\n"; print "
\n"; + print " \n"; + print " \n"; + + # query to pull out package info + # + $q = "SELECT Packages.*, IF(ISNULL(PackageID), 0, COUNT(*)) AS Popularity "; + $q.= "FROM Packages LEFT JOIN PackageVotes "; + $q.= "ON Packages.ID = PackageVotes.PackageID "; + $has_where = 0; + if ($L) { + $q.= "WHERE LocationID = ".intval($L)." "; + $has_where = 1; + } + if ($C) { + if (!$has_where) { + $q.= "WHERE CategoryID = ".intval($C)." "; + $has_where = 1; + } else { + $q.= "AND CategoryID = ".intval($C)." "; + } + } + if ($K) { + if (!$has_where) { + $q.= "WHERE (Name LIKE '".mysql_escape_string($K)."%' OR "; + $q.= "Description LIKE '%".mysql_escape_string($K)."%') "; + $has_where = 1; + } else { + $q.= "AND (Name LIKE '".mysql_escape_string($K)."%' OR "; + $q.= "Description LIKE '%".mysql_escape_string($K)."%') "; + } + } + + $q.= "GROUP BY PackageID "; + switch ($SB) { + case 'c': + $q.= "ORDER BY CategoryID ASC, Name ASC, LocationID ASC "; + break; + case 'l': + $q.= "ORDER BY LocationID ASC, Name ASC, CategoryID ASC "; + break; + default: + $q.= "ORDER BY Name ASC, LocationID ASC, CategoryID ASC "; + break; + } + $q.= "LIMIT ".intval($O).", ".intval($PP); + $result = db_query($q, $dbh); + if (!$result) { + print $q."
\n"; + print __("No packages matched your search criteria."); + } else { + + # print out package search results + # + print "
\n"; + print "\n"; + print "\n"; + print " \n"; + print " \n"; +# print "\n"; + print "\n"; + print "
\n"; + print " \n"; + print " \n"; + +# for ($i=0; $row = mysql_fetch_assoc($result); $i++) { +# (($i % 2) == 0) ? $c = "data1" : $c = "data2"; +# print "
\n"; +# +# } + print "Yippie! You found some packages!"; + + print "
\n"; + print "
\n"; + } + + print "
\n"; -- cgit v1.2.3-24-g4f1b