cerberus478 Posted October 2, 2011 Share Posted October 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/ Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Im not sure what you are asking? Do the drop down boxes contain the correct information or is the problem on the receiving page? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274876 Share on other sites More sharing options...
cerberus478 Posted October 2, 2011 Author Share Posted October 2, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274879 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Have you tried outputting the $_POST results to see if what you expect is being passed? echo '<pre>' , print_r($_POST,true) , '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274880 Share on other sites More sharing options...
cerberus478 Posted October 2, 2011 Author Share Posted October 2, 2011 No I haven't. Where would I put that? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274882 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Somewhere in the body your search.php file.. Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1274883 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 Hi I tried that and nothing happened Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275139 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275143 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 I only get this Array ( [region_id] => 1 [lifestyle_id] => [resort_facility_id] => [submitButtonName] => Go ) Which is what I selected, but not the information Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275147 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Have you written the code to get the information from what you selected? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275151 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 Isn't it the code in the search.php that I got on here Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275154 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 The code you have pasted there shows no usage of the $_POST variables. From the code it looks like you are using a class to to display the information, is this correct? Can you post the entire search.php file here. Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275155 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 yep I am using classes and that is the entire search.php file Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275157 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275159 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 When I put that code in the beginning or the end I get 327671 and if I put it any where else I get nothing. Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275160 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275161 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275163 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 Ok, context makes things a little easier to understand whats going on. So from the code you have posted are you getting any output? Does $this->_params['list'] contain any values? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275167 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 $this->_params['list'] is suppose to get all the resorts in the database but when i use p($this->_params['list']); it doesn't give me anything Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275171 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 You mean print_r? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275173 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 yep Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275175 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 When you say NOTHING do you mean a blank page or an empty array? Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275176 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 nothing Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275178 Share on other sites More sharing options...
Buddski Posted October 3, 2011 Share Posted October 3, 2011 A blank page is usually a sign that you have an error in your code somewhere. You will need to enable error_reporting at the entry point of your script, if not already done so. Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275179 Share on other sites More sharing options...
cerberus478 Posted October 3, 2011 Author Share Posted October 3, 2011 but i'm only getting numbers Quote Link to comment https://forums.phpfreaks.com/topic/248256-drop-down-boxes/#findComment-1275180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.