有一个小问题。我有这 3 个函数,这些函数在 DB 中进行搜索。但是,该搜索仅给出类别中的一个元素(当我们有 2 个或更多时)。
例如,如果我们有 1,2,3 搜索只给我们 1。如果我们删除 1,它将是 2 等等。
有什么建议么?
这是3个功能
function displayList($clause) {
$clause = ' m.active=1 && g.active=1 && '.$clause;
$pageSize = 12;
$pageNo = isset($_GET['page'])? (int)$_GET['page']:0;
$qr = "SELECT count(DISTINCT m.id) FROM #tyregoods g, #tyremodels m WHERE m.id = g.owner_id && $clause";
$q = $this->execSQL($qr);
list($count) = $q->get();
$pageCount = ceil($count / $pageSize);
if (!$pageCount) $pageCount = 1;
if ($pageCount<=$pageNo) return false;
$offset = $pageNo * $pageSize;
list($sortV, $sort) = $this->getSort();
/*$q = $this->execSQL("SELECT m.id as modelid, m.icon, m.name, m.season, g.id, width, profile, diameter, studed, indx, side, remains, price
FROM #tyregoods g, #tyremodels m WHERE m.id = g.owner_id && $clause
ORDER BY $sortV LIMIT $pageSize OFFSET $offset ");*/
$q = "SELECT m.id as modelid, m.icon, m.name, m.season, g.id, width, profile, diameter, studed, indx, side, remains, price
FROM #tyregoods g, #tyremodels m WHERE m.id = g.owner_id && $clause GROUP BY m.id
ORDER BY $sortV LIMIT $pageSize OFFSET $offset";
$q = $this->execSQL($q);
$xml = '';
while ($data = $q->getAssoc()) {
$xml.=prop2xml($data);
}
return "<goodslist page='$pageNo' pagesize='$pageSize' pages='$pageCount' sort='$sort'>$xml</goodslist>";
}
function displayBySize() {
$params = $this->kernel->getModul('tyreparams');
$clause = $this->getSQLClause($params);
if ($clause['where'] == '') return '<noparams/>';
$xml = $this->displayList($clause).$params->display();
return "<search>$xml</search>";
}
function getSQLClause($params, $except = array()) {
$cl = array();
foreach($params->params as $id=>$param)
if ($param['value']!='' && !in_array($id, $except)){
$vl = trim($param['value']);
if ('vendor' == $id) {
$cl[] = "m.owner_id IN (SELECT ts.id FROM td_tyres ts WHERE ts.active=1 AND ts.id='$vl')";
}
else {
$pos = strpos($vl, '-');
if ($pos === 0) $pos = strpos($vl, '-', 1);
if ($pos) {
$lo = substr($vl, 0, $pos);
$hi = substr($vl, $pos + 1);
$t = "$id >= '$lo' && $id <= '$hi'";
}
else
$t = "$id = '$vl'";
if ($id == 'PCD') {
$t2 = str_replace('PCD', 'PCD2', $t);
$cl[] = "(($t) || ($t2))";
} else
$cl[] = $t;
}
}
return implode('&&', $cl);
}
UPD
SQL query -
SELECT m.id as modelid, m.icon, m.name, m.season, g.id, width, profile, diameter,
studed, indx, side, remains, price FROM td_tyregoods g, td_tyremodels m WHERE m.id =
g.owner_id && m.active=1 && g.active=1 && width = '245'&&profile = '50'&&m.owner_id IN
(SELECT ts.id FROM td_tyres ts WHERE ts.active=1 AND ts.id='13') GROUP BY m.id ORDER BY
name LIMIT 12 OFFSET 0
这个查询在 mysql 控制台中给出了我们在站点上的确切信息。查询中的问题...