Jump to content

URGENT! need help in multiple search


superbogel

Recommended Posts

guys i am currently repairing my frens website and now i stumble accross a problem in their search engine

 

its a handphone website

 

currently i cant search correctly

i have tried to correct it but still no clue can someone pls help

here is the code

 

if ( isset( $_GET['n'] ) OR isset( $_GET['key'] )){

if ( isset($_GET['price_min'], $_GET['price_max']) OR isset( $_GET['key'] )){

	if (isset( $_GET['key'] )){

		$key	= clean_form($_GET['key']);

		if ( $key != '' )

			$where_key = "AND a.`name` LIKE '%$key%' ";			

	}

	if (isset( $_GET['network'] )){

		$network	= clean_form($_GET['network']);

		if ( $network != '' )

			$where_network = "AND a.`network` = '$network' ";

	}

	if (isset( $_GET['radio'] )){

		$radio	= clean_form($_GET['radio']);

		if ( $radio != '' )

			$where_radio = "AND (b.`spec_detail_id` = 69 AND b.`detail` LIKE '%radio%' ) ";

	}

	if (isset( $_GET['camera'] )){

		$camera	= clean_form($_GET['camera']);

		if ( $camera != '' )

			$where_camera = "AND (b.`spec_detail_id` = 57 AND b.`detail` != 'No' OR b.`detail` != '-' OR b.`detail` != null ) ";

	}

	if (isset( $_GET['hsdpa'] )){

		$hsdpa	= clean_form($_GET['hsdpa']);

		if ( $hsdpa != '' )

			$where_hsdpa = "AND (b.`spec_detail_id` = 18 AND b.`detail` != 'No' OR b.`detail` != '-' OR b.`detail` != null ) ";

	}

	if (isset( $_GET['memory'] )){

		$memory	= clean_form($_GET['memory']);

		if ( $memory != '' )

			$where_memory = "AND (b.`spec_detail_id` = 12 AND b.`detail` != 'No' OR b.`detail` != '-' OR b.`detail` != null ) ";			

	}

	if (isset( $_GET['wifi'] )){

		$wifi	= clean_form($_GET['wifi']);

		if ( $wifi != '' )

			$where_wifi = "AND (b.`spec_detail_id` = 19 AND b.`detail` != 'No' OR b.`detail` != '-' OR b.`detail` != null ) ";			

	}

	if (isset( $_GET['bluetooth'] )){

		$bluetooth	= clean_form($_GET['bluetooth']);

		if ( $bluetooth != '' )

			$where_bluetooth = "AND (b.`spec_detail_id` = 20 AND b.`detail` != 'No' OR b.`detail` != '-' OR b.`detail` != null ) ";			

	}

	if (isset( $_GET['brand'] )){

		$brand	= clean_form($_GET['brand']);

		if ( $brand != '' AND $brand != '-' )

			$where_brand = "AND (a.`brand_id` = '$brand') ";			

	}

	if (isset( $_GET['price_min'], $_GET['price_max'] )){

		$price_min	= clean_form($_GET['price_min']);

		$price_max	= clean_form($_GET['price_max']);

		if ( $price_min != '-' AND $price_min != ''){

			$where_price_store = "AND (a.`price_store` > $price_min) ";

			$where_price_used = "OR (a.`price_used` > $price_min) ";

		}

		if ( $price_max != '-' AND $price_max != ''){

			$where_price_store .= " AND (a.`price_store` < $price_max) ";

			$where_price_used .= "AND (a.`price_used` < $price_max) ";

		}

	}



	if (isset( $_GET['price_range'] )){

		$price_range = $_GET['price_range'];

		if ($price_range == '12'){

			$price_min	= '1000000';

			$price_max	= '2000000';

		} else if ($price_range == '23'){

			$price_min	= '2000000';

			$price_max	= '3000000';

		} else if ($price_range == '34'){

			$price_min	= '3000000';

			$price_max	= '4000000';

		} else if ($price_range == '45'){

			$price_min	= '4000000';

			$price_max	= '5000000';

		} else if ($price_range == '5'){

			$price_min	= '5000000';

			$price_max	= '-';

		} else if ($price_range == '-'){

			$price_min = '-';

			$price_max = '-';

		}



		if ( $price_min != '-' ){

			$where_price_range_store = "AND (a.`price_store` > $price_min) ";

			$where_price_range_used = "OR (a.`price_used` > $price_min) ";

		}

		if ( $price_max != '-' ){

			$where_price_range_store .= " AND (a.`price_store` < $price_max) ";

			$where_price_range_used .= "AND (a.`price_used` < $price_max) ";

		}

	}





	$q .= 'SELECT a.`hook`,a.`name`,a.`price_market`,a.`price_store`,a.`pic_small1` FROM `cellphone` AS a ';

	$q .= 'LEFT JOIN `cellphone_spec` AS b ';

	$q .= 'ON a.`hook` = b.`hook` ';

	$q .= 'WHERE 1 ';

	$q .= $where_key;

	$q .= $where_network;

	$q .= $where_radio;

	$q .= $where_camera;

	$q .= $where_hsdpa;

	$q .= $where_memory;

	$q .= $where_wifi;

	$q .= $where_bluetooth;

	$q .= $where_brand;

	$q .= $where_price_store;

	$q .= $where_price_used;

	$q .= $where_price_range_store;

	$q .= $where_price_range_used;

	$q .= ' GROUP BY a.`hook` ';

	print $q;

	$r = mysql_query( $q, $l ) or err( 'query failed:<br />'.$q );

	$t = mysql_num_rows( $r );

Link to comment
https://forums.phpfreaks.com/topic/160448-urgent-need-help-in-multiple-search/
Share on other sites

the error is that all the products is being displayed instead that its being sort by the check buttons

 

the sql look like this :

SELECT a.`hook`,a.`name`,a.`price_market`,a.`price_store`,a.`pic_small1`

FROM `cellphone` AS a

LEFT JOIN `cellphone_spec` AS b ON a.`hook` = b.`hook`

WHERE 1 AND

a.`name` LIKE '%nokia%' AND a.`network` = 'gsm' AND

(b.`spec_detail_id` = 69 AND b.`detail` LIKE '%radio%' ) AND

(b.`spec_detail_id` = 57 AND b.`detail` != 'No') AND

(b.`spec_detail_id` = 18 AND b.`detail` != 'No') AND

(b.`spec_detail_id` = 12 AND b.`detail` != 'No') AND

(b.`spec_detail_id` = 19 AND b.`detail` != 'No') AND

(b.`spec_detail_id` = 20 AND b.`detail` != 'No')

GROUP BY a.`hook`

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.