Return to Snippet

Revision: 16073
at July 24, 2009 23:28 by iloveitaly


Initial Code
function createIDList($idList, $dbFieldName) {
	if(count($idList) == 0) return '';
	
	$orString = '';
	
	foreach($idList as $id) {
		$orString .= "{$dbFieldName} = '{$id}' OR ";
	}
	
	return substr($orString, 0, -4);
}

// ex:
$query = "SELECT * FROM table_name WHERE ".createIDList(array(array('id_field' => 1), array('id_field' => 2)));

Initial URL

                                

Initial Description

                                

Initial Title
Create SQL OR ID List

Initial Tags
database, sql, list

Initial Language
PHP