示例#1
0
function find($inFindCol, $inFind = '', $inOb = '', $inFindFrom = 0, $inFindForward = true, $inFullText = true)
{
    global $table;
    // build order by clause
    $desc = (bool) getPostString("desc");
    if (!$inOb) {
        $inOb = getOrderBy();
    }
    if ($inOb) {
        $inOb = "`" . $inOb . "`";
    }
    $orderby = $inOb ? " ORDER BY {$inOb} " . ($desc ? " DESC" : "") : "";
    // update inputs from post
    if (!$inFind) {
        $inFind = getPostString('findText');
    }
    if (!$inFindCol) {
        $inFindCol = getPostString('findCol');
    }
    if (empty($inFindFrom)) {
        $inFindFrom = getPostString('findFrom');
    }
    $ff = getPostString('findForward');
    if ($ff) {
        $inFindForward = strtolower($ff) == 'true' ? true : false;
    }
    $ft = getPostString('findFullText');
    if ($ft) {
        $inFullText = strtolower($ft) == 'true' ? true : false;
    }
    // get find data
    $f = findData($inFindCol, $inFind, $orderby, $inFullText);
    $pk = getPk();
    // execute query
    $where = buildFindWhere($f, $pk->index, 'f');
    $query = "SELECT Row, f FROM (SELECT @row := @row + 1 AS Row, {$pk->name} as f FROM `{$table}` {$orderby}) AS tempTable {$where}";
    mysql_query('SET @row = -1;');
    if (!($result = mysql_query($query))) {
        error("failed to perform query: {$query}. " . mysql_error());
    }
    // return row number
    return findRow(getArray($result), $inFindFrom, $inFindForward);
}
示例#2
0
文件: kbase.php 项目: rknield/kbase
$retType = null;
if (isset($_GET['r'])) {
    $retType = $_GET["r"];
} else {
    if (isset($_POST['r'])) {
        $retType = $_POST["r"];
    }
}
$tbName = array();
$findData = array();
$args = array();
switch ($retType) {
    case "q":
        global $tbName;
        $tbName[] = "questions";
        break;
    case "qa":
        global $tbName;
        $tbName[] = "questions";
        $tbName[] = "answers";
    case "vc":
        global $tbName;
        $tbName[] = "questions";
}
//print_r(findData($tbName));
if ($retType != "vc") {
    $jsonData = findData($tbName);
    print_r(json_encode($jsonData));
} else {
    setCount($tbName);
}