Jump to content

jay.barnes

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jay.barnes's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Worked great - thanks! So, am I correct about the function only being able to be used on a variable once?
  2. Hi all, I've gotten some great help from people here in the past, and just return with one question: I've got a field in a DB that contains a string of hyphen-separated values: "Accordion-Bass(Upright)-Bass-Bassoon" I pull that string through a MySQL query, which ends up in the array key "$currentuser['Skills']" Based on that string, I want to check a series of check-boxes to see whether a particular string is present in the array key, and, if so, check the corresponding box: <input name="M-Accordian" type="checkbox" value="Accordion-" <?PHP if (strpos($currentuser['Skills'],"Accordion-") == "true") echo "checked=\"checked\"";?>/>Accordion <br /> <input name="M-UpBass" type="checkbox" value="Bass (Upright)-" <?PHP if (strpos($currentuser['Skills'],"Bass (Upright)-") == "true") echo "checked=\"checked\"";?> />Bass (upright) <br /> <input name="M-Bass" type="checkbox" value="Bass-" <?PHP if (strpos($currentuser['Skills'],"Bass") == "true") echo "checked=\"checked\"";?> />Bass <br /> <input name="M-Bassoon" type="checkbox" value="Bassoon-" <?PHP if (strpos($currentuser['Skills'],"Bassoon-") == "true") echo "checked=\"checked\"";?> />Bassoon <br /> However, whenever I load the form, despite the presence of the strings, only the first checkbox will ever correctly load checked. Can "strpos" only be invoked on a variable once, after which it can no longer be used? Thanks, and please let me know if you need more info to work from! Howver
  3. Still researching this issue.... I think I've found the criteria that I'm looking for, would like some help with my syntax, though.... function hasNumbers(string) { var regex = /\d/g; return regex.test(string); } function validateOriginFormat() { var error = ""; if ( (document.load_search.Search_Origin_Type_1.checked == true)&& (!hasNumbers(document.load_search.Search_Origin_Radius_Point.value))&&//if the value of the field has no numbers in it, and, thusly is not an american or canadian zip code (document.load_search.Search_Origin_Radius_Point.value.substr(-3, 1)//and the third to last character of the value is not a letter or number ) { error = "Please use a valid city/state format (example: Boston, MA or Toronto, ON) in Step 3!\n"//recognize the the intended input was a city and state, but the proper format of "City, ST" was not used. } return error; } Anyone able to point me in the right direction in regards to where I'm going wrong with my syntax? Thanks!
  4. Hi, all! I've got a field that I need users to fill with either: 1. An American postal code (example: "47582") 2. A Canadian postal code (example: "A8G 1F4") 3. A city/state abbreviation (example: "Atlanta, GA", or "Quebec City, QC") I know how to make sure that they only enter numbers in the field, but that would not allow option 2 or 3. The best validation checks I can make are: if the entry is all letters (and possibly spaces or commas) - assume the entry is a city/state combination - make sure that there are two letters after the comma or final space in the string if the entry is all numbers - assume the the entry is an American postal code - make sure that there are only five digits in the entry if the entry is a combination letters and numbers - Assume the entry is a Canadian postal code - make sure that the entry follows the "A1A 1A1" format so, that's my question: How do I make the form element "document.form.text_field.value" look for such values? Thank you!
  5. Still trying to find a way to address this issue.... Recap: I have a table, which lists several loads, and their pickup origins, structured as such (irrelevant fields removed): Table: LOADS ------------------------------------------------------ | Load_Num | Origin_City | Origin_State | Origin_Zip | |----------|-------------|--------------|------------| | 1 | Miami | FL | 33101 | | 2 | Toronto | ON | M4B 1V4 | | 3 | Boston | MA | 02108 | | 4 | Vancouver | BC | V5T 1Y9 | ------------------------------------------------------ My users can type a zip code, and a radius of up to 200 miles into two fields, and execute a search which: 1. Finds the lat and lon of the entered zip code, searching two tables on my DB (Can ZIPs, and USA ZIPs) 2. Runs the appropriate equation to find all zip codes that are within that radius 3. Converts the array of zip codes to a string, with values separated by a comma. 3. Executes a query of the "Loads" table, searching for all loads that originate in any one of those zip codes. An example query would be "SELECT* FROM Available_Loads WHERE Origin_Zip IN (a,whole,lotta,zip,codes') ORDER BY ".$_GET['OrderBy']" When I was only conducting searches in the US, I wouldn't have much of a problem getting results, as I'd only be searching through, say < 1000 zips total. However, once I introduced Canada to the mix (yeah, blame Canada!), the size of my queries grew exponentially, due to their ZIP code system (for example, in my table of Canadian ZIPs, Toronto, ON, has 13,959 ZIP codes in that one city *alone*). This is causing my MySQL server to choke on queries that involve Canadian ZIPs, and not complete the script. I was wondering if there was any way I could tweak my search code, so that, instead of searching the "Loads" board for all loads that contain all those ZIP codes, I could execute a search that would just match against the City/State combinations. (forgive my lack of proper syntax, here, but I guess the query would look something like "SELECT* FROM Available_Loads WHERE Origin_City, Origin_State IN ('Springfield, VA','Arlington, VA') ORDER BY ".$_GET['OrderBy']" I think that would make it more efficient, but I'm not sure how I'd go about making sure that the cities and states "stick together" during the execution of a search (For example, if I'm doing a search for all loads within 500 miles of Springfield, IL, and some locations in VA show up, the query doesn't return "Springfield, VA" as a possible result, simply because "Springfield" happened to be one of the matching cities, and "VA" happened to be among the matching states.) Below is the code that runs the data transformations from user input to the "Loads" board query execution. Can anyone offer up some suggestions on how I might be able match against city/state combinations as opposed to zip codes? Thanks for any suggestions you may have! -Jay // retrieve the zip code and distance values from the form $zip_code = $_POST['Search_Origin_Radius_Point']; $miles = $_POST['Search_Origin_Radius']; $query_search_origin_zip = "SELECT latitude, longitude FROM zip_codes_usa WHERE zip_code = '$zip_code' UNION SELECT latitude, longitude FROM zip_codes_can WHERE zip_code = '$zip_code' LIMIT 0,1"; $search_origin_zip = mysql_query($query_search_origin_zip, $Connection) or die("Unable to execute query $query_search_origin_zip: ".mysql_error()); $row_search_origin_zip = mysql_fetch_assoc($search_origin_zip); $totalRows_search_origin_zip = mysql_num_rows($search_origin_zip); $array_search_origin_zip = mysql_fetch_array($search_origin_zip); if ($totalRows_search_origin_zip == 0) { // the zip code does not exists echo "The origin zip code was not found in the database"; } else { // the zip code was found so process the data $lat = $row_search_origin_zip['latitude']; $lon = $row_search_origin_zip['longitude']; // get the min/max latitudes and longitudes for the radius search $lat_range = $miles / 69.172; $lon_range = abs($miles / (cos($lon) * 69.172)); $min_lat = $lat - $lat_range; $max_lat = $lat + $lat_range; $min_lon = $lon - $lon_range; $max_lon = $lon + $lon_range; // apply the min/max coordinates to the sql query to only select those items within range $query_search_origin_range = "SELECT DISTINCT zip_code, city_name, state_abbrev, latitude, longitude FROM zip_codes_usa WHERE ((latitude >= $min_lat AND latitude <= $max_lat) AND (longitude >= $min_lon AND longitude <= $max_lon)) AND `longitude` != '0.000000' AND `latitude` != '0.000000' UNION SELECT DISTINCT zip_code, city_name, state_abbrev, latitude, longitude FROM zip_codes_can WHERE ((latitude >= $min_lat AND latitude <= $max_lat) AND (longitude >= $min_lon AND longitude <= $max_lon)) AND `longitude` != '0.000000' AND `latitude` != '0.000000' ORDER BY zip_code DESC"; $search_origin_range = mysql_query($query_search_origin_range, $Connection) or die(mysql_error()); $row_search_origin_range = mysql_fetch_assoc($search_origin_range); $totalRows_search_origin_range = mysql_num_rows($search_origin_range); while ($array_search_origin_range = mysql_fetch_array($search_origin_range)) { // check the distance to make sure it's less than the entered radius $origin_dist = distance($lat, $lon, $array_search_origin_range["latitude"], $array_search_origin_range["longitude"]); if ($origin_dist <= $miles) { // the zip code is within the requested radius so process the results $search_origin_city[] = $array_search_origin_range["city_name"]; $search_origin_zip_code[] = $array_search_origin_range["zip_code"]; $origin_distance[$array_search_origin_range["zip_code"]] = $origin_dist; } } } //compile results into an array $search_origin_zip_code = array_values($search_origin_zip_code); //remove empty array values, if any foreach($search_origin_zip_code as $key => $value) { if($value == "") { unset($search_origin_zip_code[$key]); } } //remove duplicate values, if any $search_origin_zip_code = array_unique($search_origin_zip_code); //convert array values back into a string $search_origin_zip_code = implode('\', \'',$search_origin_zip_code); //add array string to session data, so search can be performed again and/or revised, if needed if (!($_SESSION['search'])) { $_SESSION['search'] = "locked"; $_SESSION['search_origin_radius'] = $_POST['Search_Origin_Radius']; } //execute main board query $query_AvailableLoads = "SELECT * FROM Loads WHERE Origin_Zip IN ('$_SESSION[search_origin_zip_code]') ORDER BY ".$_GET['OrderBy']; $AvailableLoads = mysql_query($query_AvailableLoads, $Connection) or die("Unable to execute main query".mysql_error()); $row_AvailableLoads = mysql_fetch_assoc($AvailableLoads); $totalRows_AvailableLoads = mysql_num_rows($AvailableLoads);
  6. Yeah, you were more on point - my USA zip table has closer to 43000 records. I may have to see what other options I have at my disposal regarding Canada and their micro-managed zip code system. :-p Thanks for the advice!
  7. MySQL server version: 5.0.51a (on an IIS server running Plesk control panel) I'm running a query to try and locate shipments available within a specific radius of a zip code. When I was just using USA (approx 70,000 zips on the table), the query ran fine, no matter what radius I specified (anywhere between 25, 50, 100, 150, or 200 miles). Now that I updated my code to include Canada (has its own table of approx 830,000 zips), whenever I try to execute a radius search that happens to include Canadian zip codes, any radius search larger than 50 miles returns an error that "The MySQL server has gone away". It sounds to me that the server is choking on the query (not that I can blame it, with the number of zip codes Canada seems to have). I have tried mitigating this by going into my.cfg (found in "c:\Parllels\Plesk\MySQL\Data") and changing the "max_allowed_packet" setting from 1M to 1024M (restarting the server after making the changes, just to make sure it took), but that didn't seem to have any effect. I was also thinking of retooling the query to only search for city names and state names instead of zip codes (as there are fewer cities out there than zip codes), but I'm not sure how to phrase the zip code query to output cities linked to states in a manner that I could use in the main query (for example, searching for loads within 25 miles of Springfield, VA, doesn't return loads in Springfield, IL, simply because it has a city named "Springfield" in it). I suspect it would have something to do with "GROUP BY", and nesting the city in the state criteria using the "GROUP BY" modifier, but I have yet to get satisfactory results with that. Here's an example of the main load search query below, which may help illustrate things a bit (I omitted all the zip codes in the query, for readability's sake) SELECT Broker_JobNum, Username, Entry_UpdateDateTime, Broker_CompanyName, Shipment_Type, Required_Equipment, Load_Length, Load_Weight, Available_Loads.Origin_City, Origin_State, Origin_Zip, PU_Date, Dest_City, Dest_State, Dest_Zip, Delivery_Date, Frequency FROM Available_Loads" WHERE Required_Equipment IN ('V') AND Shipment_Type LIKE 'TL' AND Action != 'D' AND Username != 'demo' AND Status != 'inactive' AND Origin_Zip != '00000' AND Origin_Zip != '99999' AND Origin_Zip IN ('$AWHOLELOTTAZIPCODES') ORDER BY ".$_GET['OrderBy'] Are there any suggestions anyone may have which may help me either lighten the load on the server by restructuring the query (may be unlikely), or elevating the MySQL server's load tolerance in a way that I just haven't figured out yet? Thanks, and please let me know if you need me to supply any more pertinent info! -Jay
  8. Hello! I've kind of hit a wall, here, and may need some help from some of the more seasoned veterans of MySQL, here I have a table with > 10,000 records, like such, as an example: |Name |Luggage |Origin_Country |Origin_State |Origin_City |Dest_Country |Dest_State |Dest_City | |__________________________________________________________________________________________________| |Bob |CO |USA |ME |Portland |USA |RI |Providence| |Jack |Trunk |CAN |ON |Toronto |USA |TX |Dallas | |Mary |Handbag |CAN |BC |Vancouver |CAN |ON |Timmons | |Ed |Backpack|USA |AZ |Phoenix |USA |MI |Detroit | |Jen |Trunk |USA |FL |Orlando |CAN |NS |Halifax | |Rich |CO |CAN |NS |Amherst |USA |CT |Hartford | ____________________________________________________________________________________________________ And, I've also put together a form, to search the table, allowing users to select multiple values for a field: Luggage: [] CO [] Trunk [] Handbag [] Backpack ORIGIN [] CAN []ALL CAN STATES []AB []BC []MB []NB []NL []NS []NT []NU []ON []PE []QC []SK []YT [] USA []All USA states []AK []AL []AR []AZ []CA []CO []CT []DC []DE []FL []GA []HI []IA []ID []IL []IN []KS []KY []LA []MA []MD []ME []MI []MN []MO []MS []MT []NC []ND []NE []NH []NJ []NM []NV []NY []OH []OK []OR []PA []RI []SC []SD []TN []TX []UT []VA []VT []WA []WI []WV []WY [] MEX []All MEX states []AGS []BCN []BCS []CAM []CHIH []CHIS []COAH []COL []DF []DGO []GRO []GTO []HGO []JAL []MEX []MICH []MOR []NAY []NL []YUC []ZAC DESTINATION COUNTRY [] CAN []ALL CAN STATES []AB []BC []MB []NB []NL []NS []NT []NU []ON []PE []QC []SK []YT [] USA []ALL USA STATES []AK []AL []AR []AZ []CA []CO []CT []DC []DE []FL []GA []HI []IA []ID []IL []IN []KS []KY []LA []MA []MD []ME []MI []MN []MO []MS []MT []NC []ND []NE []NH []NJ []NM []NV []NY []OH []OK []OR []PA []RI []SC []SD []TN []TX []UT []VA []VT []WA []WI []WV []WY [] MEX []ALL MEX STATES []AGS []BCN []BCS []CAM []CHIH []CHIS []COAH []COL []DF []DGO []GRO []GTO []HGO []JAL []MEX []MICH []MOR []NAY []NL []YUC []ZAC Now, how do I phrase a MySQL query to search through a table, using the contents of the arrays that the checkboxes return? I was thinking of using a "foreach" statement for every condition, but, with the potential complexity of such a search, up against a table with so many records it seems to time out PHP after 30 seconds- I'm just thinking that there may be a more efficient way to construct the query and its parameters. Anybody have any suggestions? Thank you!
  9. AAhhh...I understand now...I thought ($cityandstate, ",") was setting the comma as the delimiter - I read the manual page wrong. I"m basically trying to find out if a string contains a comma, and, if it does, execute some commands I'll look at strpos(), and see if that better suits my needs. Thanks for your help, guys!
  10. $cityandstate = "New York, NY"; if (preg_match(",",$cityandstate)) { echo "true"; } returns "Warning: preg_match() [function.preg-match]: No ending delimiter ',' found in test.php on line 37" what am I doing wrong, here???
  11. You know? I knew about the "_parent" name, but I wasn't sure if, when you loaded a pop-up window, whether it would create a static, solid parent-child link between the two windows, or if it might lose the relation, and simply spawn a new window. Thanks for the suggestions! The experiments continue.....
  12. An additional thought while turning this over in my head - I think I figured out how to pass the form variables to the parent page - set the POST variables as SESSION variables.... Now I just have to figure out how to send a refresh/reload command to the parent window.
  13. This may be a hybrid HTML/PHP/MySQL/Javascript(possibly even AJAX) question, so please forgive me if I exit the scope of this forum anywhere... SCENARIO: I have a browser window that has a dynamic table, showing the results of a MySQL query. On this page is a link that a user can click on that will pop-up a search window with a form on it that will allow him/her to search the DB by altering the parameters of the MySQL query in the original, parent window. (or at least that's what I'm hoping to make it do! ) My question is, how can I pass the form data from the pop-up window back to the parent window, so I can pass my new search parameters on the page? Additionally, after passing the form data back to the parent window, I'd have to reload the parent window, in order to apply the new search parameters, right? How would I go about telling the parent window to reload after "submit" is clicked on the pop-up window? Thanks for any suggestions you guys might be able to offer - I've just about run out of ideas!
  14. Thank you for the offers of assistance, everyone, but I (finally) got it figured out: I created a query for the accounts, and then created a repeating table based on that query, creating cells for the truck count . In that cell, I put in a DB query looking for recordsets where the truck count username equalled "$row_AccountQuery[username]" (the username called in that row). So, every time the row repeated, the "$row_AccountQuery[username]" would change to equal the username called out in that row, subsequently returning the appropriate number. I hope that made sense, and I wasn't rambling too much. Thanks again for the assistance, though! Even though the suggestions didn't get me the desired output, it jogged my mind into comprehending, interpreting, and understanding how queries and repeating regions worked!
  15. Sure, I'll try! Table: Accounts Username Bob Jim [br /] Table: Available_Loads Username Available_Until Bob 2009-3-10 Bob 2009-2-20 Bob 2009-7-15 Jim 2009-2-25 Bob 2009-5-16 Bob 2009-3-4 Bob 2009-3-23 Jim 2009-6-6 Bob 2009-4-9 Bob 2009-5-10 Bob 2009-2-14 Bob 2009-7-16 [br /] Table: Available_Trucks Username Available_Until Bob 2009-3-2 Bob 2009-4-8 Bob 2009-5-15 Jim 2009-3-7 Jim 2009-4-4 Bob 2009-3-6 Bob 2009-5-19 Bob 2009-3-14 Bob 2009-4-15 Jim 2009-4-9 Bob 2009-3-18 Bob 2009-5-22 Bob 2009-4-30 Bob 2009-3-9 Jim 2009-5-12 Hope this helps clarify things, and thanks for checking this out!
×
×
  • 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.