co.ador Posted November 23, 2009 Share Posted November 23, 2009 <?php $strSQL = ''; $arrRestaurants = array(); // place holder form data variables $strName = ''; $strZipCode = ''; $arrFoodTypes = array(); $arrOfferings = array(); // food types and offerings drop down build arrays $arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array()); $arrRestaurantsOfferings = array(); Please can anybody explain some of what is happening above thank you.... or give me some reference to where i can read and understand a little bit what's is scripted above Quote Link to comment https://forums.phpfreaks.com/topic/182600-need-to-know-what-this-code-lines-means-thank-you/ Share on other sites More sharing options...
mikesta707 Posted November 23, 2009 Share Posted November 23, 2009 That is just variables being defined. What exactly don't you understand about that script? Here is a tutorial Quote Link to comment https://forums.phpfreaks.com/topic/182600-need-to-know-what-this-code-lines-means-thank-you/#findComment-963739 Share on other sites More sharing options...
co.ador Posted November 23, 2009 Author Share Posted November 23, 2009 I can see arrays inside arrays $strSQL = ''; What's the definition of the variable above? what is equal to? How is that value inside the commas is used later on through the script what for? $arrRestaurants = array(); Then the $arrRestaurants variable definitions arrays, What understand is that variable will have severals values depending on where the array is in this case. is that corrrect? The value of $arrRestaurants will depend on where the array is... Well May I ask you how does array(); get values for $arrRestaurants? // place holder form data variables What is place holder form? $strName = ''; $strZipCode = ''; $arrFoodTypes = array(); $arrOfferings = array(); Again this variables will be the same as the ones I have questionsd you about above. // food types and offerings drop down build arrays What does the author means by drop down build arrays? $arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array()); The $arrRestaurantsFoodTypes value is an array which contain two arrays right? well what values=>array(); means that 'values' is a variable which will have the array as a value? the same for output? well that I don't understand well.. Well those are my question, I will greatly appreciate your input guys... Thank you. $arrRestaurantsOfferings = array(); Quote Link to comment https://forums.phpfreaks.com/topic/182600-need-to-know-what-this-code-lines-means-thank-you/#findComment-963741 Share on other sites More sharing options...
mikesta707 Posted November 23, 2009 Share Posted November 23, 2009 What's the definition of the variable above? what is equal to? How is that value inside the commas is used later on through the script what for? The variable, in that case, would be an empty string. Then the $arrRestaurants variable definitions arrays, What understand is that variable will have severals values depending on where the array is in this case. is that corrrect? The value of $arrRestaurants will depend on where the array is... Well May I ask you how does array(); get values for $arrRestaurants? Kind of. You define whatever is inside the array with the array function $myArray = (1, 2, 3); I can access the stuff in that array by using the square bracket operators "[]" like so echo $myArray[0];//echos 1 echo $myArray[1];//echos 2 $myArray[1] = 4; echo $myArray[1];//echos 4 The numbers inside the brackets are called keys. They determine which value in the array you are accessing There is a link in my sig that has a tutorial on arrays. I highly suggest you check that link out, or the tutorial i linked to in my earlier post. // food types and offerings drop down build arrays What does the author means by drop down build arrays? I'm assuming he means that he is going to use the array to build an HTML drop down box with some other code. But it's hard to say without seeing the other code. Seeing those few lines out of context can be misleading. $arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array()); The $arrRestaurantsFoodTypes value is an array which contain two arrays right? well what values=>array(); means that 'values' is a variable which will have the array as a value? the same for output? well that I don't understand well.. Yes it is an array of two arrays. but values isn't really a variable, its an array key. this is called an associative array because the array keys are a string, rather than numbers like in my first example. This means that instead of typing $array[0] to get the first array, you could type $arrRestaurantsFoodTypes['value']; and that would be the inner array. as far as output, if you echoed the line above, it would echo "Array()" because simple echo statements can't echo an array. you can use print_r($arrRestaurantsFoodTypes['value']) to see the structure of the inner array Quote Link to comment https://forums.phpfreaks.com/topic/182600-need-to-know-what-this-code-lines-means-thank-you/#findComment-963745 Share on other sites More sharing options...
co.ador Posted November 24, 2009 Author Share Posted November 24, 2009 Hey guys mikesta this is the whole code... This is the whole code can you please give an specific or general overview of your opinion and understanding so I can catch some of this complex code. <?php $strSQL = ''; $arrRestaurants = array(); // place holder form data variables $strName = ''; $strZipCode = ''; $arrFoodTypes = array(); $arrOfferings = array(); // food types and offerings drop down build arrays $arrRestaurantsFoodTypes = array('values'=>array(),'output'=>array()); $arrRestaurantsOfferings = array(); /* fill food types array - replace with query $arrResult = mysql_query('SELECT restaurant_food_types_id,name FROM RESTAURANT_FOOD_TYPES'); while($arrRow = mysql_fetch_assoc($arrResult)) { $arrRestaurantsFoodTypes['values'][] = $arrRow['restaurant_food_types_id']; $arrRestaurantsFoodTypes['output'][] = $arrRow['name']; } */ $arrRestaurantsFoodTypes['values'][] = ''; $arrRestaurantsFoodTypes['output'][] = '--'; $arrRestaurantsFoodTypes['values'][] = 3; $arrRestaurantsFoodTypes['output'][] = 'Asian'; $arrRestaurantsFoodTypes['values'][] = 4; $arrRestaurantsFoodTypes['output'][] = 'American'; $arrRestaurantsFoodTypes['values'][] = 87; $arrRestaurantsFoodTypes['output'][] = 'Swiss'; /* fill offerings array - replace with query $arrResult = mysql_query('SELECT restaurant_offerings_id,name FROM RESTAURANT_OFFERINGS'); while($arrRow = mysql_fetch_assoc($arrResult)) { $arrRestaurantsOfferings[] = $arrRow; } */ $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>56,'name'=>'Delivery'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>23,'name'=>'Eat-in'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>233,'name'=>'Wi-Fi'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>67,'name'=>'Buffet'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>12,'name'=>'TV'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>43,'name'=>'Parking'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>90,'name'=>'Catering'); $arrRestaurantsOfferings[] = array('restaurant_offerings_id'=>51,'name'=>'Take Out'); // reset form $boolReset = isset($_POST['frmSearch']) && isset($_POST['frmSearch']['reset'])?true:false; if($boolReset === false && isset($_POST['frmSearch'])) { // Extract POST variables and escape $strName = isset($_POST['frmSearch']['name'])?/*mysql_real_escape_string(*/$_POST['frmSearch']['name']/*)*/:''; $strZipCode = isset($_POST['frmSearch']['zipcode'])/*mysql_real_escape_string(*/?$_POST['frmSearch']['zipcode']/*)*/:''; $arrFoodTypes = isset($_POST['frmSearch']['food_types'])?$_POST['frmSearch']['food_types']:array(); $arrOfferings = isset($_POST['frmSearch']['offerings'])?$_POST['frmSearch']['offerings']:array(); // WHERE clause filters $arrSQLFilters = array(); // Zipcode filter if(!empty($strZipCode)) { $arrSQLFilters[] = sprintf( "r.zip LIKE '%s'" ,"%$strZipCode%" ); } // Restaurants name filter if(!empty($strName)) { $arrSQLFilters[] = sprintf( "r.name LIKE '%s'" ,"%$strName%" ); } // Food types filter if(!empty($arrFoodTypes) && !empty($arrFoodTypes[0])) { $arrSQLFilters[] = sprintf( 'r.restaurants_id IN (SELECT DISTINCT restaurants_id FROM RESTAURANTS_TO_RESTAURANTS_FOOD_TYPES WHERE restaurants_food_types_id IN (%s) GROUP BY restaurants_id HAVING COUNT(DISTINCT restaurants_id) = %u)' ,/*mysql_real_escape_string(*/ implode(',',$arrFoodTypes) /*)*/ ,count($arrFoodTypes) ); } // Offerings Filter ie. eat-in, lunch, dinner, etc if(!empty($arrOfferings)) { $arrSQLFilters[] = sprintf( 'r.restaurants_id IN (SELECT DISTINCT restaurants_id FROM RESTAURANTS_TO_RESTAURANT_OFFERINGS WHERE restaurant_offerings_id IN (%s) GROUP BY restaurants_id HAVING COUNT(DISTINCT restaurants_id) = %u)' ,/*mysql_real_escape_string(*/ implode(',',$arrOfferings) /*)*/ ,count($arrOfferings) ); } // Build search query and embed filters $strSQL = sprintf( 'SELECT r.* FROM RESTAURANTS r %s' ,empty($arrSQLFilters)?'':' WHERE '.implode(' AND ',$arrSQLFilters) ); /* Run search query $arrResult = mysql_query($strSQL); while($arrRow = mysql_fetch_assoc($arrResult)) { $arrRestaurants[] = $arrRow; } */ } ?> <form name="frmSearch" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <fieldset> <legend>Find A Restuarant</legend> <ul> <li class="restaurants-name"> <label for="restaurants-name">Name</label> <input type="text" name="frmSearch[name]" value="<?php echo $strName; ?>" id="restaurants-name"> </li> <li class="restaurants-zipcode"> <label for="restaurants-zipcode">Zip</label> <input type="text" name="frmSearch[zipcode]" value="<?php echo $strZipCode; ?>" maxlength="5" id="restaurants-name"> </li> <?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> </li> <?php } ?> <?php if(!empty($arrRestaurantsOfferings)) { ?> <li class="restaurants-offerings"> <ul> <?php foreach($arrRestaurantsOfferings as $arrRestaurantsOffering) { printf( '<li class="restaurants-offerings-%u"> <input type="checkbox" name="frmSearch[offerings][]" value="%u" id="restaurants-offerings-%u"%s> <label for="restaurants-offerings-%u">%s</label> </li>' ,$arrRestaurantsOffering['restaurant_offerings_id'] ,$arrRestaurantsOffering['restaurant_offerings_id'] ,$arrRestaurantsOffering['restaurant_offerings_id'] ,in_array($arrRestaurantsOffering['restaurant_offerings_id'],$arrOfferings)?' checked="checked"':'' ,$arrRestaurantsOffering['restaurant_offerings_id'] ,$arrRestaurantsOffering['name'] ); } ?> </ul> </li> <?php } ?> <li class="submit"> <input type="submit" value="Submit" name="frmSearch[submit]"> </li> <li class="reset"> <input type="submit" value="reset" name="frmSearch[reset]"> </li> </ul> </fieldset> </form> <?php // print search query if(!empty($strSQL)) printf('<p>%s</p>',$strSQL); /* Dump out all resturants search data foreach($arrRestaurants as $arrRestaurant) { .... }?> Quote Link to comment https://forums.phpfreaks.com/topic/182600-need-to-know-what-this-code-lines-means-thank-you/#findComment-964441 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.