Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. you are just throwing more code at this without a plan. listing out all your fields - $array['form_id'], array['reserv'], $array['code'], ... is the same as assigning the the whole $array, except assigning the whole array will give you the column names as the keys. you need to slow down. based on your description, you want to process the data per user_id, listing each date and the amount of time worked and display the total at the end? you would instead need to store the the values in $data using the 'user_id' as the primary key and sorting by the date (in the query) and if you have more than one entry per user_id on any date, you would need to use the date as a second array key. you would loop over the $data array, processing the entries for each user, then for each date for that user.
  2. you need to store the whole $array to your $data array so you end up with an associative array of values to keep things clear in the code. also, unless you have more than one entry for any id on a date, you don't need to use the id as an additional array index. i would go back to the code maxxd gave in reply #2 and just fix the missing ] - while($array = mysql_fetch_array($result)){ $data[$array['date']][] = $array; } lastly, you don't need any sort of recursive function to process this data. you would however, need to show us your intended end result given any input data to get any help with how to do it.
  3. knowing what error you got would help.
  4. you would implode the array to make it a comma separated list and use an IN() comparison in the query - http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in
  5. in your revised code, you are not binding (or supplying an array in the execute() method call) any variables or values for the two place-holders in the prepared query. also, you should (almost) never run queries inside of loops, even prepared queries only save a minimal amount of time in a loop because you must sill do a round-tirp to the database server to supply the values for the query, and if you were running a prepared query inside a loop, the only query statement logic inside the loop would be the call to the execute() method. by putting the prepare() statement inside the loop, you are re-preparing the query each pass through the loop and the posted code is taking twice as long to run as a non-prepared query would take. since it's not clear what you are attempting to use the result from the query to do, it's not possible to advise on the best method to use to avoid running a query inside of a loop. however, if you are going to insert new data or insert new data/update existing data, you would typically define a unique key and either just use a query like INSERT IGNORE ... or an INSERT ... ON DUPLICATE KEY UPDATE ..., rather than first trying to select data to decide what to do in the code to handle the new/updated values. also, your try/catch block won't work unless you set PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION
  6. what does using var_dump($email_token); show?
  7. your first error is because you have used array names for some of your form fields, so you are submitting arrays of post variables, not just scaler post variables and that code wasn't designed to handle arrays. whatever code you end up with needs to take into account the structure of the data it is dealing with. in addition to what has already been mentioned about the code, you should only (properly) escape (or cast numerical values) the data as it is being put into the sql query statement (or use prepared queries) so that the original data can be used as is by the rest of the program. i didn't look into the second error since the line number mentioned in the error wasn't identified in the posted code, but this error is probably also related to using array names for the form fields. so, the same comment would apply - whatever code you end up with needs to take into account the structure of the data it is dealing with.
  8. sorry, but that's useless information. by not telling us what it does do (even telling us it resulted in a blank page is a clue that helps narrow down the problem), we cannot help you with the many possible things that could go wrong with any piece of code. the only apparent issue with the posted code is it doesn't have any logic in it to tell you if the fopen() statement has failed.
  9. your statement of what and why you are doing it makes no sense. having a second table, that apparently holds duplicate email and password fields, will in no way prevent someone from logging into someone else's account. all this has done is to create duplicate information that must now be maintained. authenticating someone, involves inputting and checking values that only they should know. you are getting (actually posting) the visitor's email and password. your program flow should be to validate those two inputs and check if you have a matching row in your members table, using the same processing/hashing algorithm that you used when the visitor registered. the goal of the authentication process is to identify the visitor and get their user's id and any other 'static' information, such as the username, and store those values in session variables in order to remember who the current authenticated visitor is. these are the only values you should store in session variables. storing the password makes no sense because you have already authenticated the visitor and the password is no longer relevant. lastly, something even tells me that the value you are identifying as an email isn't. your preg_replace() statement won't permit an email and referring to the value later as $manager/$_SESSION["manager"] says it means something else. if the email form field and database table field is not an email, don't name it such. give it a name that matches its actual purpose (especially if you want someone else to help you with what your code is doing.)
  10. the posted code makes little sense, both because it doesn't show the relevant information leading up to that point (what query are you running, where is $id coming from and what does it mean, what is in $tbl_name...) and the while(){} logic would require there to be the same number of rows for both results sets. however, the query against whatever is in $tbl_name implies there is one row from that query, with a specific id, so at best, your loop will only produce output the first time through the loop. i'm guessing this code starts where your previous thread ended and that $tbl_name is 'customers'? your goal when retrieving related data from a database is to do it using one query. the query you ended up with at the end of your previous thread does/or should return the 'customers' table email and name for the specified id. all you need to do is select those in the query and referenced them in the php code.
  11. that's because your php version isn't >= 5.3 or you are not using the mysqlnd driver, both are required for that function to exist and to work. you will need to read the information about using bind result that Jacques1 posted a link to in reply #5
  12. just off of the top of my head, assuming the page is using session variables to remember who the visitor is, it's possible that the variation of the host-name/sub-domain (www. vs no www.) that's being used in the redirect back to your site doesn't match the variation of the host-name/sub-domain where the session variables were created at and there's no matching session. is the domain variation in the URL before you goto the payment processor the same as when you get redirected back? to debug what the page is doing, start by setting php's error_reporting to E_ALL and either set display_errors to ON or set log_errors to ON, then see what if any php detected errors are either displayed or logged. edit: also is the protocol http vs https the same in the URL on your site before going to the payment processor and after the redirect back to your site?
  13. if you are using the mysqli_query() function, you MUST use the corresponding mysqli_fetch_xxxxx() functions. you cannot mix mysqli and mysql (no i) functions.
  14. the error you are getting typically occurs when you have closed the database connection and try to use the connection, i.e. $con was a connection, but that connection was closed prior to the code you have shown. also, mysqli statements will only throw exceptions if you have used the mysqli_report() function/method to configure it to do so. your current code is a mix of the PDO logic you were previously using (why did you not keep using that?) and mysqli and as a result your catch(...){...} statement isn't going to work with mysqli exceptions (you also have an $ex vs $e variable name mismatch.)
  15. there's nothing technically wrong in the code you have shown that would (likely) cause that error. it would require referencing an array in a string context. are you sure that's the correct file at the drive letter and path mentioned in the error message?
  16. a) are you sure you even need the php_zip extension? it's only required by PHPExcel in some cases. b) what sort of problem are you having with PHPExcel? it might not have anything to do with the zip extension. c) have you checked if the php.ini that you are changing is the one the php is using? the Loaded Configuration File output from a phpinfo() statement is the php.ini that php is using. d) is the zip extension currently being loaded? there wound be a section present for it in the output from a phpinfo() statement. e) have you checked your web server's error log for any relevant php_zip.dll errors, that was mentioned as something to do in the replies above in this thread? f) have you done or checked the other things mentioned in the replies above in this thread? g) we only see the information that you supply in your posts and when you don't include information about what is occurring and what you have checked and what symptoms or errors you are getting, we cannot help because we don't have any feedback from you that narrows down the problem.
  17. what would make you think javasciprt/jquery would have anything to do with a comparison not matching values in the server-side code? if you read my reply above in this thread, you will see that the hash value you are storing during registration isn't what you think.
  18. the single = in your posted code is a problem, because the conditional test will always be true if the post variable is set, regardless of the value in it. for your solution, i was hoping that you would rearrange the code on your page so that it was correctly organized as a web page.
  19. if you copy/pasted this code from somewhere, it can have non-printing characters or characters with a character encoding that is not straight ascii. delete and retype everything between the final T in SELECT to the initial F in FROM.
  20. you cannot output ANYTHING to the browser before a header() statement. your javascirpt code is output that is being sent to the browser and cannot come before a header(), a session_start(), setcookie()... statement. the only reason this works on your development system is because php thought it would be fun to waste your time developing code that wouldn't run on every system. your development system has an output_buffer setting in the php.ini that should be turned off, so that code you develop will work, with regards to header() statements, on every system. stop and start your web server on your development system to get any change made to the php.ini to take effect.
  21. the problem isn't the paypal script. it's how you are trying to include the file. you are trying to use the URL of that file. that won't work for two reasons - 1) your server is configured so that you cannot use a URL in an include statement. 2) if your server did allow a URL to be used in an include statement, only the output from that file would included. the php code would not be included. to include the php code in that file, you must use a file system path on your server, NOT a URL.
  22. this might be a good time to slow down and first define what it is you are trying to accomplish, then what inputs you have available, what preprocessing you need to do on those inputs, and what result or output you are trying to produce, both for when the inputs are what you expect, and when they are not. starting with your registration code. you have two password fields being submitted. why? and what processing did you define for those two password fields during registration? the reason i ask, is you have concatenated the values from those two password fields, hashed the concatenated value, and stored one of the password fields and the hash in your database table. this makes no sense.
  23. the ftp address is used for transferring files via FTP (File Transfer Portocol.) this has nothing to do with a database server. the database server's host(name) would be something like mysql.your_web_host.com or just the ip address of the mysql server. your web host should have a faq that specifies this or it is usually displayed in the tool/page where you are creating database user, passwords, and managing your databases and tables (i.e phpmyadmin or a similar tool.)
  24. for that particular script, you can cache the distance calculations and there are few other micro-optimizations you can perform inside the loops and in the distance function (this takes ~30 seconds for 9 points, and ~1.7 seconds for 8 points on my development system, 8 point was ~3.5 seconds using the unmodified code) - <?php class TSP { private $locations = array(); // all locations to visit private $longitudes = array(); private $latitudes = array(); private $shortest_route = array(); // holds the shortest route private $shortest_routes = array(); // any matching shortest routes private $shortest_distance = 0; // holds the shortest distance private $all_routes = array(); // array of all the possible combinations and there distances // add a location public function add($name,$longitude,$latitude){ $this->locations[$name] = array('longitude'=>$longitude,'latitude'=>$latitude); } //LAT LON Location - added method for parameter order public function _add($latitude,$longitude,$name){ $this->locations[$name] = array('longitude'=>$longitude,'latitude'=>$latitude); } // the main function that des the calculations public function compute(){ $locations = $this->locations; foreach ($locations as $location=>$coords){ $this->longitudes[$location] = $coords['longitude']; $this->latitudes[$location] = $coords['latitude']; } $locations = array_keys($locations); $this->all_routes = $this->array_permutations($locations); $cache = array(); foreach ($this->all_routes as $key=>$perms){ $i=0; $total = 0; $n = count($this->locations)-1; foreach ($perms as $value){ if ($i<$n){ $source = $perms[$i]; $dest = $perms[$i+1]; if(isset($cache[$source][$dest])){ $dist = $cache[$source][$dest]; } elseif (isset($cache[$dest][$source])) { $dist = $cache[$dest][$source]; } else { $dist = $this->distance($this->latitudes[$source],$this->longitudes[$source],$this->latitudes[$dest],$this->longitudes[$dest]); $cache[$source][$dest] = $dist; } $total+=$dist; } $i++; } $this->all_routes[$key]['distance'] = $total; if ($total<$this->shortest_distance || $this->shortest_distance ==0){ $this->shortest_distance = $total; $this->shortest_route = $perms; $this->shortest_routes = array(); } if ($total == $this->shortest_distance){ $this->shortest_routes[] = $perms; } } } // work out the distance between 2 longitude and latitude pairs function distance($lat1, $lon1, $lat2, $lon2) { if ($lat1 == $lat2 && $lon1 == $lon2) return 0; $theta = $lon1 - $lon2; $r_l1 = deg2rad($lat1); $r_l2 = deg2rad($lat2); $dist = sin($r_l1) * sin($r_l2) + cos($r_l1) * cos($r_l2) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 69.09; return $miles; } // work out all the possible different permutations of an array of data private function array_permutations($items, $perms = array()){ static $all_permutations; if (empty($items)) { $all_permutations[] = $perms; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); $this->array_permutations($newitems, $newperms); } } return $all_permutations; } // return an array of the shortest possible route public function shortest_route(){ return $this->shortest_route; } // returns an array of any routes that are exactly the same distance as the shortest (ie the shortest backwards normally) public function matching_shortest_routes(){ return $this->shortest_routes; } // the shortest possible distance to travel public function shortest_distance(){ return $this->shortest_distance; } // returns an array of all the possible routes public function routes(){ return $this->all_routes; } } $s = microtime(true); $tsp = new TSP; //$tsp->_add(39.25, 106.30, 'Leadville,CO'); // 9th point (~30 seconds) $tsp->_add(39.18, 103.70, 'Limon,CO'); $tsp->_add(38.50, 107.88, 'Montrose,CO'); $tsp->_add(38.28, 104.52, 'Pueblo,CO'); $tsp->_add(39.53, 107.80, 'Rifle,CO'); $tsp->_add(38.53, 106.05, 'Salida,CO'); $tsp->_add(40.48, 106.82, 'Steamboat Sp,CO'); $tsp->_add(37.25, 104.33, 'Trinidad,CO'); $tsp->_add(40.00, 105.87, 'Winter Park,CO'); $tsp->compute(); $e = microtime(true); $t = $e - $s; echo "Time: $t<br>"; echo "<pre>"; echo 'Shortest Distance: '.$tsp->shortest_distance(); echo '<br />Shortest Route: '; print_r($tsp->shortest_route()); echo '<br />Num Routes: '.count($tsp->routes()); echo '<br />Matching shortest Routes: '; print_r($tsp->matching_shortest_routes()); //echo '<br />All Routes: '; //print_r($tsp->routes()); having the distance calculation between all the pairs of points (the $cache contents in the above) brings up the possibility of using the following algorithm - http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm you could just produce all the pairs of points (not all the possible permutations of all the points) and calculate the distance between each pair of points, then use the Dijkstra algorithm (i found a handful of php implementations while searching) on those distances.
  25. we can only help you with your actual code. posting anything else in a thread just sidetracks the problem.
×
×
  • 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.