These functions may be of interest which are used in my DasaBookCafe.tk book search:
Code:
/* =================================
# Validate and clean input text
# $params = 'search for multiple words go here';
==================== */
function getParams
(
$params=NULL
)
:array
{
$result = NULL;
# REMOVE DOUBLE SPACES
while (strpos($params, ' ') ) {
$params = str_replace(' ', ' ', $params);
}
# CONVERT TO ARRAY
$result = explode(' ', $params);
if( empty($result) ):
$result[] = $params;
endif;
return (array) $result;
}//
/* ============================================
# Parse User's input input into a string
============================================== */
function getSqlWhere
(
$aParams, $cols
)
:string
{
$result = '';
foreach($aParams as $i2 => $param):
if($i2 > 0):
$result .= ' AND ';
endif;
$result .= "
CONCAT($cols)
LIKE '%$param%'
";
endforeach;
return (string) $result;
}
/* ===========================================
# Conbine two SQL Statements - ORDER IMPORTANT
=========================================== */
function getCombinedCount
(
$table,
$sWhere,
$cols
)
:string
{
$uLIMITREX = uLIMITREX;
$result = <<< ____TMP
SELECT COUNT(*) AS `recNo`
FROM `$table`
WHERE $sWhere
;
____TMP;
return (string) $result;
}
/* ===========================================
# Conbine two SQL Statements - ORDER IMPORTANT
=========================================== */
function getCombinedRows
(
$table,
$sWhere,
string $cols,
$uLIMITREX
)
:string
{
$result = <<< ____TMP
SELECT $cols
FROM `$table`
WHERE $sWhere
LIMIT 0, $uLIMITREX;
____TMP;
return (string) $result;
}