Jump to content

Drop down boxes


cerberus478

Recommended Posts

Hi

 

I have 3 drop down boxes and I want my boxes to go to another page when I select them and click go. For example if I click western cape I want it to give me all the resorts in western cape and if I click western cape and beaches I want it to give me all the resorts that are in the western cape that are next to beaches. I have been able to populate the drop down boxes with information and it can go to another page but it doesn't give me the information I want.

 

This is my drop down boxes code

 

<script type="text/javascript">

function showGo(){



      var region_id = $("#region_id").val();

      var lifestyle_id = $("#lifestyle_id").val();

      var resort_facility_id = $("#resort_facility_id").val();



      if((region_id != 'false') || (lifestyle_id != 'false') || (resort_facility_id != 'false')){



            $("#destinationSearchButton").css('display', 'block');

            

      }else{



            $("#destinationSearchButton").css('display', 'none');

      }







</script>


<form action="/pages/search/" method="post">

		<select class="formSelect" name="region_id" id="region_id" size="1" tabindex="1" onchange="showGo()">
	<option label="Region">
	<?php

		$regions_model = new regions_model('regions');
		$regions = $regions_model -> get_all();

		 foreach($regions as $region){
		$name = $region['name'];
		$id	=$region['id'];

		$select = "SELECT $id, $name FROM regions";
		 		echo "<option value='$id'>$name</option>";
		 } ?>
	</option>

	</select>

<select class="formSelect" name="lifestyle_id" id="lifestyle_id" size="1" tabindex="2" onchange="showGo()">
		<option label="lifestyle">
	<?php

		$lifestyles_model = new lifestyles_model('lifestyles');
		$lifestyles = $lifestyles_model -> get_all();

		 foreach($lifestyles as $lifestyle){
		$name = $lifestyle['name'];
		$id = $lifestyle['id'];

		$select = "SELECT $name FROM lifestyles";
		 		echo "<option name='$id'>$name</option>";
		 } ?>
	</option>
	</select>


<select class="formSelect" name="resort_facility_id" id="resort_facility_id" size="1" tabindex="3" onchange="showGo()">
		<option label="Facilities & Amenities">
	<?php

		$resort_facilities_model = new resort_facilities_model('resort_facilities');
		$resort_facilities= $resort_facilities_model -> get_all();

		 foreach($resort_facilities as $resort_facility){
		$name = $resort_facility['name'];
		$id = $resort_facility['id'];

		$select = "SELECT $name FROM resort_failities";
		 		echo "<option name='$id'>$name</option>";
		 } ?>
	</option>
	</select>

	<input class="formInputButton" type="submit" name="submitButtonName" id="destinationSearchButton" value="Go" tabindex="4"/ style="display: none;" />
	</form>
</div>	

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/
Share on other sites

I think think the problem is in the recieving page, because the drop down boxes has the correct information.

Here is my search.php

 

<div class="top-head-2nd"><h2><div class="right-link" style="text-align:right;"><a href="javascript:;" onClick="history.go(-1)">« Go Back</a></div></h2></div>
<?php 
if(!empty($this->_params['list'])){
?>
<div style="clear:both;">
	<div id="region-listings">
		<div class="inhoud">
			<?php 
			foreach ($this->_params['list'] as $resort){
			?>
			<table width="100%" border="0" cellspacing="0" cellpadding="8">
				<tr>
					<td width="76%" bgcolor="#404040"><h3><?php echo $resort['name'] ?></h3></td>
					<td width="24%" bgcolor="#FF9900"><a href="<?php echo $this->get_uri('/resorts/view/'.$resort['id']) ?>">View Resort Profile »</a></td>
				</tr>
				<tr>
					<td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td width="17%"><img src="/image.php?path=<?php echo $resort['image_path'] ?>&w=135&h=89" /></td>
							<td style="line-height:155%;" width="83%" valign="top">
							<?php 
							if(!empty($resort['cheapest_listing'])){
							?>
							  <strong>Shares available from <span class="orange">R<?php echo $resort['cheapest_listing'] ?></span> per share</strong><br />
							<?php
							} 
							if(!empty($resort['lifestyles'])){
								?>
							<span class="grey">	
								<?php

								echo 'Lifestyles: ';

								$comma = '';

								foreach($resort['lifestyles'] as $lifestyle){

									echo $comma.$lifestyle['name'];

									$comma = ', ';
								}
								?>
							</span><br>	
								<?php
							}
							if(!empty($resort['no_of_listings'])){
							?>
							<strong>(<?php echo $resort['no_of_listings'] ?> Listings)</strong></td>
							<?php 
							}
							?>
						</tr>
						<tr>
							<td colspan="2"> </td>
							</tr>
					</table></td>
				</tr>
			</table>
			<?php 
			}
			?>
		</div>
	</div>
</div>
<?php 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274879
Share on other sites

So if you do this (on your search.php page)

echo '<pre>' , print_r($_POST,true) , '</pre>';
<div class="top-head-2nd"><h2><div class="right-link" style="text-align:right;"><a href="javascript:;" onClick="history.go(-1)">« Go Back</a></div></h2></div>
<?php 
if(!empty($this->_params['list'])){
?>

You get no output?

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275143
Share on other sites

Umm, I think you may have missed something.. Are you getting any output at ALL on your search.php page?

I am assuming not as your code (if that is your entire search.php) will throw Fatal errors as you are using $this out of context.

If you turn on error reporting

error_reporting(E_ALL);
ini_set('display_errors',1);

You will see what I mean.

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275159
Share on other sites

I have absolutely no idea what that number is supposed to mean..

However, a PHP class is structured as below.

class SimpleClass
{
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
        echo $this->var;
    }
}

Nowhere in the search.php page is there anything that comes close to resembling a class.

In any case, where are you expecting the information in $this->_params['list'] to be coming from?

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275161
Share on other sites

I have this in my pages.controller.php

 

public function search(){

	$resorts_model = new resorts_model('resorts');

	$this->_params['title'] = "Resorts ";
	$this->_params['list'] = array();

	if(is_numeric($this->_params['region_id'])){

		$region = $this->_model->get_one("SELECT name FROM regions WHERE id = {$this->_params['region_id']}");
	}

	if(is_numeric($this->_params['lifestyle_id'])){

		$lifestyle = $this->_model->get_one("SELECT name FROM lifestyles WHERE id = {$this->_params['lifestyle_id']}");
	}

	if(is_numeric($this->_params['resort_facility_id'])){

		$resort_facility = $this->_model->get_one("SELECT name FROM resort_facilities WHERE id = {$this->_params['resort_facility_id']}");
	}

	$possible_conditions = array('region_id' => "resorts.region_id = {$this->_params['region_id']}",
								 'lifestyle_id' => "resorts.id = lifestyles_resorts.resort_id AND lifestyles_resorts.lifestyle_id = {$this->_params['lifestyle_id']}",
								 'resort_facility_id' => "resorts.id = resorts_resort_facilities.resort_id AND resorts_resort_facilities.resort_facility_id = {$this->_params['resort_facility_id']}");

	$combinations = array(array('region_id', 'lifestyle_id', 'resort_facility_id'),
						  array('region_id', 'lifestyle_id'),
						  array('region_id', 'resort_facility_id'),
						  array('lifestyle_id', 'resort_facility_id'),
						  array('region_id'),
						  array('lifestyle_id'),
						  array('resort_facility_id'));
						  
	$i = 0;

	$in_str = $this->get_in_industry_string();

	while(empty($this->_params['list']) && $i < count($combinations)){

		$conditions = array();

		for($j = 0; $j < count($combinations[$i]); $j++){

			if(is_numeric($this->_params[$combinations[$i][$j]])){

				$conditions[$combinations[$i][$j]] = $possible_conditions[$combinations[$i][$j]];
			}
		}

		$resorts = $resorts_model->get_all($conditions);

		if(!empty($resorts)){

			foreach($resorts as $resort){

				if(!$this->has_listings('resorts', $resort['id'])){

					continue;
				}

				$resort['lifestyles'] = $resorts_model->get_lifestyles($resort['id']);

				$resort['cheapest_listing'] = $resorts_model->get_cheapest_listing($resort['id'], $in_str);

				$this->_params['list'][] = $resort;
			}
		}

		$i ++;
	}

	foreach($conditions as $id_name => $condition){

		$name = str_replace('_id', '', $id_name);

		if($name == 'region'){

			$this->_params['title'] .= ' in ';

		}elseif(!strstr($this->_params['title'], ' with ')){

			$this->_params['title'] .= ' with ';

		}else{

			$this->_params['title'] .= ' and ';
		}

		$this->_params['title'] .= $$name;
	}
}

Link to comment
https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275163
Share on other sites

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.