PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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") )
count($result); returns 1 but i do not believe that.
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