co.ador Posted January 3, 2010 Share Posted January 3, 2010 <?php $strName = isset($_REQUEST['frmSearch']['name'])?mysql_real_escape_string($_REQUEST['frmSearch']['name']):''; $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])? mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):''; $strState = isset($_REQUEST['frmSearch']['zipcode'])?mysql_real_escape_string ($_REQUEST['frmSearch']['state']):'';/*)*/; ?> if(!empty($strZipCode)){ $query4 = "SELECT state, zip, county FROM stores WHERE (zip= '$strZipCode'); $result = mysql_query($query4); $arrstate = mysql_fetch_array($result); echo '<div class="information"><label>County:</label> <div>'. $arrstate['county']. '</div> <label>State:</label> <div>'. $arrstate['state']. '</div> <label>Zip Code:</label> <div>'. $arrstate['zip']. '</div></div> <br><br>'; } In the code above there is info $_RESQUESTed from a form coming from page1.php then it is use to display the fields County,State and zip from the table stores. as it is set up this fileds will display only WHERE (zip= '$strZipCode'); now it means that if a user select information from another fields and leave zipcode input fields empty the fields County,State and zip won't display. Now how can I set the WHERE Clause to also display when users only input data in the state input field at the form in page1.php or Name Or only input data in the Name input field at the form in page1.php and leave the other iunput field of the form empty? How that WHERE clause would look like ? Help please....... Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 $query4 = "SELECT state, zip, county FROM stores WHERE zip= '$strZipCode' OR name='$strName' OR state='$strState'"; You will need to remove the !empty($strZipCode) check or make it encompass the other vars aswell.. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 Thank you very much Buddski again it is working but not for the arrays like $strState ? Will I have to call it by its index instead of the variable? Instead of <?php state='$strState' ?> Then call it like.. <?php state=". $_GET['state']. "?> Buddski thank you.. Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 $strName = isset($_REQUEST['frmSearch']['name'])?mysql_real_escape_string($_REQUEST['frmSearch']['name']):''; $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])? mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):''; $strState = isset($_REQUEST['frmSearch']['zipcode'])?mysql_real_escape_string ($_REQUEST['frmSearch']['state']):''; Its because your $strState is checking for the zip code Try this.. $strName = isset($_REQUEST['frmSearch']['name'])?mysql_real_escape_string($_REQUEST['frmSearch']['name']):''; $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])? mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):''; $strState = isset($_REQUEST['frmSearch']['state'])?mysql_real_escape_string ($_REQUEST['frmSearch']['state']):''; Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 still, show I put array(); after the else condition ? :array(); Since strState is an array? right now if only submit the form with inputting the state input then it won't display the fields state, zip and county Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 Your posting an array to the script? Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 What do you mean by posting an array to script? Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 You are saying that $strState is an array. Which you are getting through the $_REQUEST global... Im a little confused as to what you are saying.. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 I was guessing it was an array since it was not displaying the fields from store, not sure... even though in page1.php is not set as an array. $strName = ''; $strZipCode = ''; $strState = ''; $arrFoodTypes = array(); $arrOfferings = array(); Then the arraStates, $arrStates = array('','AL','AK','AZ','AR','CA','CO','CT','DE','FL','GA','HI','ID','IL','IN','IA','KS','LA','ME','MD','MA','MI','MN','MS','MO','MT','NE','NV','NV','NH','NJ','NM','NY','NC','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY',); Form in page1.php </li> <?php if(!empty($arrStates)) { ?> <li class="restaurants-state"> <label for="restaurants-state">State</label> <select name="frmSearch[state][]" id="restaurants-state" style="width:40px;"> <?php foreach($arrStates as $strStateAbb) { printf( '<option value="%s"%s>%s</option>' ,$strStateAbb ,strcmp($strState,$strStateAbb) == 0?' selected="selected"':'' ,strcmp($strStateAbb,'')==0?'--':$strStateAbb ); } ?> </select> </li> then in page2.php I receive it like <?php <?php $strName = isset($_REQUEST['frmSearch']['name'])?mysql_real_escape_string($_REQUEST['frmSearch']['name']):''; $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])? mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):''; $strState = isset($_REQUEST['frmSearch']['state'])? mysql_real_escape_string($_REQUEST['frmSearch']['state']):''; $arrFoodTypes = isset($_REQUEST['frmSearch']['food_types'])? ($_REQUEST['frmSearch']['food_types']):array(); $arrOfferings = isset($_REQUEST['frmSearch']['offerings'])?mysql_real_escape_string($_REQUEST['frmSearch']['offerings']):array(); ?> ?> and so on... Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 Ok your state select field name doesnt need the [] unless mulitple select is enabled.. If you remove the [] and just have frmSearch[state] it should work.. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 so that [] was making it an array? that was the solution but why it wouldn't then display the fields? then it was passing through the form to page2.php as what? Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 3, 2010 Share Posted January 3, 2010 putting the [] on the end of the name turns the post into an array.. Its used when select fields have multiple enabled. Quote Link to comment Share on other sites More sharing options...
co.ador Posted January 3, 2010 Author Share Posted January 3, 2010 indeed it has multiples select it is an list of zip that will display and be available when users click on the little triangle to select the state. But still it won't display the fields of the table store if it has the [] was wondering if it would be need for the future. Two more input field and both are arrays(); one is a select input and another are checkboxes. They won't display the fields of store either now it is obviously an array and it goes like this. Have to say the are not in the WHERE clause. <?php $strName = ''; $strZipCode = ''; $strState = ''; $arrFoodTypes = array(); $arrOfferings = array(); // food types and offerings drop down build arrays $arrRestaurantsFoodTypes = array('values'=>array(''),'output'=>array('--')); //Offerings check boxes build array $arrRestaurantsOfferings = array(); ?> Form in page1.php <?php <?php } ?> <?php if(!empty($arrRestaurantsFoodTypes)) { ?> <li class="restaurants-food-types"> <label for="restaurants-food-types">Food Type</label> <select name="frmSearch[food_types][]" id="restaurants-food-types"> <?php foreach($arrRestaurantsFoodTypes['values'] as $intIndex=>$intFoodTypesId) { printf( '<option value="%s"%s>%s</option>' ,$intFoodTypesId ,in_array($intFoodTypesId,$arrFoodTypes)?' selected="selected"':'' ,$arrRestaurantsFoodTypes['output'][$intIndex] ); } ?> </select> <?php if(!empty($arrRestaurantsOfferings)) { ?> <ol> <li class="restaurants-offerings"> <?php foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) { printf( '<input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s /> <span class="checkboxes23">%s</span><br />' ,$arrRestaurantsOffering['restaurant_offerings_id'] ,$arrRestaurantsOffering['restaurant_offerings_id'] ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':'' ,$arrRestaurantsOffering['name'] ); } ?> </li> </ol> <?php } ?> ?> the food types is a Select and the offering is a check box both of them are arrays, Now how can I still display the fields for stores tables when either the check boxes fields are selected or the select for the foodtypes are selected Have to say that in the database both offering and foodtypes uses an many-to-many database tables that are joined by the id, and foodtype_id and offering_id. so in stores tables we have an id that is joined to footypes tables through foodtype_id and joined to offering tables through offering_id. That uses a many-to-many relationship. how can I then specify at the WHERE clause a many-to-many relationship database? The only way would be through the id of the store table. WHERE zip= '$strZipCode' OR restaurantname='$strName' OR state='$strState' OR id= '$arrFoodTypes'"; Well I don't think so since $arrFoodTypes is returning from the form as a string not as a int. This is how both input fields arrFoodTypes and arrOfferings gets filled to display in the form for users to select. <?php // fill food types array - replace with query $arrResult = mysql_query('SELECT restaurant_food_types_id,name FROM restaurant_food_types ORDER BY name ASC'); while($arrRow = mysql_fetch_assoc($arrResult)) { $arrRestaurantsFoodTypes['values'][] = $arrRow['restaurant_food_types_id']; $arrRestaurantsFoodTypes['output'][] = $arrRow['name']; } // fill offerings array - replace with query $arrResult = mysql_query('SELECT restaurant_offerings_id,name FROM restaurant_offerings ORDER BY name ASC'); while($arrRow = mysql_fetch_assoc($arrResult)) { $arrRestaurantsOfferings[] = $arrRow; } ?> Quote Link to comment 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.