All pastes #802269 Raw Edit

Untitled

public php v1 · immutable
#802269 ·published 2007-11-30 01:02 UTC
rendered paste body
				// We don't need subqueries at all! Just query for the available/existing databases first and then pass the ID's to the XOR method.				if ( preg_match('`[%\*_"]`is', $this->data['Browse']['tags']) ) {					// Format before querying for categories.					$this->data['Browse']['tags'] = str_replace('_', '%', str_replace('*', '%', $this->data['Browse']['tags']));				}				$query = '';				foreach ( explode(' ', $this->data['Browse']['tags']) as $key => $value ) {					$query .= '`Category`.`name` LIKE \''.$value.'\' OR ';				}				$query = substr($query, 0, -3);				$categories = $this->Category->findAll($query, '`Category`.`id`');								$query = '';				$bitValue = (pow(2, count($categories))-1);				$query = 'HAVING BIT_OR(1 << FIELD( `categories`.`id`, ';				foreach ( $categories as $key => $value ) {					$query .= $categories[$key]['Category']['id'].', ';				}				$query = substr($query, 0, -2);				$query .= ')-1) = '.$bitValue;				// Find all work ID's				$query = '				SELECT DISTINCT 					`works`.`id`				FROM 					`categories` 					INNER JOIN 						`works_categories` 						ON 							`categories`.`id` = `works_categories`.`category_id`					INNER JOIN						`works`						ON							`works_categories`.`work_id` = `works`.`id`					GROUP BY 						`works`.`id`					'.$query;				$result = $this->Category->query($query);				$query = '';				foreach ( $result as $key => $value ) {					$query .= '`Work`.`id` = '.$value['works']['id'].' OR ';				}				$query = substr($query, 0, -4);				if ( !$query ) {					$this->set('works', array());				} else {					$this->set('works', $this->paginate('Work', $query));				}								$this->Session->write('Browse.tags', $this->data['Browse']['tags']);				$this->Session->write('Browse.mode', 'tags');