deansaddigh Posted January 12, 2010 Share Posted January 12, 2010 Hi guys, i have a searchBar.php script which populates counties it works on this page http://www.dhcottages.co.uk/testsite/details.php?id=75 But not any other page e.g http://www.dhcottages.co.uk/testsite/index.php heres the code for the searchBar.php <? $countySQL='SELECT DISTINCT p.county_id, c.county FROM properties p JOIN county c ON p.county_id = c.id WHERE status = \'online\' order by county ASC'; $locationcounty = $db->query($countySQL); if(!isset($arrivalDate))$arrivalDate =''; if(!isset($departure))$departure =''; if(!isset($location))$location =''; if(!isset($sleeps))$sleeps =''; if(!isset($pets))$pets =''; if(!isset($shortBreaks))$shortBreaks =''; ?> <div id="searchNav"> <div style="clear:both;">Search</div> <form method='POST' name='search' id='search' action='list.php'> <input type='text' name='arrival' class='date-pick' id="arrival" style='font-size:11px;'<? if (!empty($arrivalDate)){?>value="<?=$arrivalDate?>"<? }else{?>value="Arrival"<? }?> /> <input name='departure' id="departure" class="date-pick" type="text" style='font-size:11px;'<? if (!empty($departureDate)){?>value="<?=$departureDate?>"<? }else{?>value="Departure"<? }?> /> <select name='location' class='searchDropDown' style='margin-top:5px;'> <option value='' <? if ( $location == '' ){echo 'selected';}?>>County</option> <? foreach($locationcounty as $locationcounty2) { ?> <option value='<?=$locationcounty2{'county_id'}?>' ><?=$locationcounty2{'county'}?></option> <? } ?> </select> <select name='sleeps' class='searchDropDown'> <option value='' <? if ($sleeps == ''){echo 'selected';}?>>Sleeps</option> <option value='1'<? if ($sleeps == '1'){echo 'selected';}?>>1</option> <option value='2'<? if ($sleeps == '2'){echo 'selected';}?>>2</option> <option value='3'<? if ($sleeps == '3'){echo 'selected';}?>>3</option> <option value='4'<? if ($sleeps == '4'){echo 'selected';}?>>4</option> <option value='5'<? if ($sleeps == '5'){echo 'selected';}?>>5</option> <option value='6'<? if ($sleeps == '6'){echo 'selected';}?>>6</option> <option value='7<? if ($sleeps == '7'){echo 'selected';}?>'>7</option> <option value='8'<? if ($sleeps == '8'){echo 'selected';}?>>8</option> <option value='9'<? if ($sleeps == '9'){echo 'selected';}?>>9</option> <option value='10'<? if ($sleeps == '10'){echo 'selected';}?>>10</option> </select> <select name='pets' class='searchDropDown'> <option value=''>Pets</option> <option value='yes' <? if ( $pets == 'yes' ){echo 'selected';}?>>Yes</option> <option value='no' <? if ( $pets == 'no' ){echo 'selected';}?>>No</option> </select> <table border='0'> <tr> <td>Short Breaks</td><td><input type="checkbox" name="short" value='checked'<?=$shortBreaks?>></td> </tr> <tr> <td><a href="javascript:document.getElementById('search').submit()"><img src='images/searchSquare.gif' border='0' style='margin-left:25px; margin-top:-3px;'></a></td> </tr> </table> </form> </div> <script type='text/javascript'> $(function() { $('.date-pick').datePicker({clickInput:true}) $('#arrival').bind( 'dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#departure').dpSetStartDate(d.addDays(1).asString()); } } ); $('#departure').bind( 'dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#arrival').dpSetEndDate(d.addDays(-1).asString()); } } ); }); </script> And heres the code for the index.php so you can see maybe there is some confliciotn <?php $page_id = 'home'; $title = 'Home'; include('lib/includes/header.php'); ?> <!-- START OF MAIN CONTENT --> <? include('lib/includes/searchBar.php'); ?> <div class="topItem"><a href="list.php"><img src='images/take_a_look.jpg' border='0'></a></div> <div class="topItem"><a href="map.php"><img src='images/dorsetMap.jpg' border='0'></a></div> <div class="bottomItem"><a href="list.php?short=checked"><img src='images/short_term.jpg' border='0'></a></div> <div class="bottomItem"><a href="brochureRequest.php"><img src='images/brochure.jpg' border='0'></a></div> <BR clear='all'><BR clear='all'> </NOFRAMES> <!-- END OF MAIN CONTENT --> <?php include('lib/includes/footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/188168-option-box-include-populates-county-on-one-page-but-not-another/ Share on other sites More sharing options...
Catfish Posted January 12, 2010 Share Posted January 12, 2010 First test the result you get from the database: if ($locationcounty = $db->query($countySQL)) { // code to run if the sql query succeeded } else print('Could not get data from database. Error given: '.mysql_error().'<br/>'."\n"); So you can see if the query to the database is even working when you load index.php It looks like to me, that details.php is perhaps establishing a connection to the database first before including searchBar.php and index.php is not. Also, print_r($locationcounty); to ensure there is data in the array. And in fact on a quick second look, I can't see you calling mysql_fetch_assoc() on $locationcounty either so I can't understand how it would even work on any of the pages. Link to comment https://forums.phpfreaks.com/topic/188168-option-box-include-populates-county-on-one-page-but-not-another/#findComment-993439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.