[solved] {class} function select WHERE LIKE AND
Posted: Thu Dec 09, 2004 1:59 am
Code: Select all
function select_like( $table, $condition="", $sort="" ) {
$query = "SELECT * FROM $table";
$query .= $this->_makeWhereLike( $condition );
...........
...........ect..
function _makeWhereLike( $condition ) {
if ( empty( $condition ) )
return "";
$retstr = " WHERE ";
if ( is_array( $condition ) ) {
$cond_pairs=array();
foreach( $condition as $field=>$val )
array_push( $cond_pairs, "$field LIKE %".$this->_quote_val( $val )."%" );
$retstr .= implode( " AND ", $cond_pairs );
} elseif ( is_string( $condition ) && ! empty( $condition ) )
$retstr .= $condition;
return $retstr;
}
#calling it. *(trying hehe)
# column1 is for the LIKE and column2 is for the AND whatever ej:(age<8)
$result = $dl->select_like("table", array('column1'=>"value1",'column2'=>"value2") )as when doing a normal $field= & AND it will return one aswell. and the foreach returns the information.
however with the LIKE i get this back
Invalid argument supplied for foreach() in
Code: Select all
foreach( $result as $Rrow ) {
echo $Rrow['column'];
}