Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Andy-H

  1. function invert($number) { return (~$number + 1); }
  2. Look at the syntax highlighting echo '<textarea id="question' . $questionNo . '" name="'. $qaArray['answerText'] .'" cols="60" rows="2">' . (isset($questionNo) ? htmlentities($qaArray['answerText'], ENT_QUOTES) : '') . '</textarea>';
  3. Just a couple of glitches that occurred when I was developing the application, in case anyone's interested.
  4. People actually read the TOS? lol
  5. Fair enough but not everyone's that nice, I might see details and truncate their users table. I have selective vision, my brain doesn't even process moving the cursor to post and clicking any more, it's in my "muscle memory" lol Anyway, I see where this is going so I'll set this topic solved. lol
  6. I am willing to, but we all make mistakes from time to time. Plus what about noobs posting on here for the first time, they don't know the interface, they don't know the preview button is there, they might be to busy consciously trying not to present themselves as an idiot and overlook this. What's wrong with an SMF magic_quotes_gpc? //Edit I am willing to, but we all make mistakes from time to time. Plus what about noobs posting on here for the first time, they don't know the interface, they don't know the preview button is there, they might be to busty consciously trying not to present themselves as an idiot and overlook this. What's wrong with an SMF magic_quotes_gpc? -> I am willing to, but we all make mistakes from time to time. Plus what about noobs posting on here for the first time, they don't know the interface, they don't know the preview button is there, they might be to busy consciously trying not to present themselves as an idiot and overlook this. What's wrong with an SMF magic_quotes_gpc? See lol
  7. Yeah but it would help in a lot of cases on here, generally I use that style but keep my defines in a settings.const.php file, but I see alot of people using mysql_query(host, user, pass) on here. Could go as far as checking for variable params and *'ing out the variable definitions?
  8. I've seen a couple of people do this, and done it myself a couple of times. I know it's down to a user and it's your own fault if you forget to remove sensitive information, but it would be cool if PHPFreaks/SMF could automatically search for mysql(i)_connect, imap_open etc. and * out sensitive paramaters before it posts, I've dropped a few bricks in my time posting mysql passwords lol
  9. Ahh OK, I'll implement that tomorrow and I'm sure we'll get some feedback. Yeah, I suppose we've got issues if the user doesn't have spreadsheet software, that one will take a while lol lol thanks, overlooked that one, originally updating account settings logged users out, thanks I take it you mean like when you click on journeys? That's an easy one I'll sort that out. Thanks again =D
  10. You can change the icons by clicking on the settings tab and changing the "Device icon" option, it won't save the updates on the demo system but it does on the proper system, the designer drew the icons in photoshop, so I will need to speak to him first. You mean like a normal google maps marker? That could work, I know the giant icons are useless at high zoom levels lol The device name should come in a tooltip after about a second hovering? Or do you mean instantly in an info window? What did you think of the application? Did you check out the Journeys and reports and stuff? Also you can add custom locations on a right click. Thanks for the feedback.
  11. If anyone's been on it and the vehicles weren't moving that was because of my "node.js tracking unit emulator" crashed, I have started it up again now so they are moving again.
  12. If you've already loaded jquery you mayaswell make use of document ready: get_stats.js function get_stats(type, callback) { $.getJSON('get_stats.php', { stat : type }, function(data) { if ( data.qry.toLowerCase() != 'ok' ) { alert(data.response); return false; } callback.call(this, data.response); return false; }); }; <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="../jquery.js"></script> <script type="text/javascript" src="../get_stats.js"></script> <script type="text/javascript"> $(document).ready(function() { var secs = 3; var stats = [{ type : 'online', selector : '#online' }, { type : 'money', selector : '#money' }]; $.each(stats, function(stat) { setInterval(function() { get_stats(stat.type, function(data) { $(stat.selector).html(data); }); }, secs * 1000); }); }); </script> <body> <div id="online"><> <div id="money"><> </body> </html> PHP (get_stats.php) function respond($response, $qry = 'OK') { return json_encode(array('qry' => $qry, 'response' => $response)); } $mysqli = new mysqli('localhost', 'user', 'pass', 'db'); $stats = isset($_GET['stats']) ? $_GET['stats'] : ''; switch($stats) { case 'online' : $result = $mysqli->query("SELECT logged_in FROM accounts WHERE logged_in != 0"); echo respond($result->num_rows); exit; break; case 'money' : $result = $mysqli->query("SELECT sum(money) AS totalCurrency FROM players"); $row = $mysqli->fetch_field_direct(0); echo respond(number_format($row->totalCurrency)); exit; break; case 'default' : echo respond('Invalid arguments', 'FAIL'); exit; break; }
  13. Just finished our demo fleet tracking software, http://demo.phantominsight.co.uk, any feedback/feature ideas welcome and much appreciated. If you don't understand how to use something on there, please let me know, the plan is to add video tutorials under a help menu, but that's not implemented yet. If you find a bug please could you post your browser, browser version and operating system too, thanks.
  14. Chrome, FireFox, Opera - Linux Mint 11 - 1280 x 768 Everything seems to render fine, all in view/scrollable, tree looks fine.
  15. Because you are passing variables through the URL, so the request method is GET, and your code clearly says, if request method is POST, run code else echo error. You need to post the data via a form: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $db = mysql_connect("localhost", "*******" , "*****")or die("Error connecting to database: " . mysql_error()); $db_used = mysql_select_db("pskkorg_drp1", $db)or die("Could not select database: " . mysql_error()); $user_name = mysql_real_escape_string($_POST['username'],$db); $query = mysql_query("SELECT * FROM student WHERE Username = '$user_name'",$db) or die(mysql_error()); if(mysql_num_rows($query) == 1){ echo "Login successful, welcome back " . $user_name . ""; }else{ echo "Login unsuccessful, please ensure you are using the correct details"; } }else{ echo "Error"; } ?> <form action="" method="post"> <input type="text" name="username" ><br > <input type="submit" name="submit" > </form>
  16. But the other people here said that this involves polling? And regarding the process you mentioned, the server may stream output to the socket, what code will listen at that socket to manipulate the DOM accordingly? PHP or Javascript or Node? Sorry, I hardly know anything about sockets and stuff, so the question might seem naive. Javascript listens on the client-side. As well as the nodejs server side socketIO library, there is also a client side socketIO script that listens for the servers pushed data. Take a look at the socket.io website.
  17. No, it doesn't involve polling, lets say 3 clients are in a chat room using push technology, the server keeps an open socket to each client, client 1 sends a chat message to the server, the server processes the data and streams output to the sockets of each client, and the client is updated in real-time. Take a look at video.
  18. Yes, you can do both polling or push with node, although if you're going to be using polling, may-as-well use PHP.
  19. Should it even be a singleton then? // edit updated to normal class <?php /* @return string (encoded lat/lng) - polyline::getEncoded(-2.5675, 2.5456); @return string (encoded lat/lng's) - polyline::getEncoded(array(-2.5675, 2.5456), array(-2.5675, 2.5456)); @return string (encoded lat/lng's) - polyline::getEncoded(-2.5675, 2.5456, -2.5675, 2.5456); @return array (decoded array(lat, lng)'s) - polyline::getDecoded('zmtn_?_epn_?zmtn_?_epn_?zmtn_?_epn_?'); */ class polyline { // tracks number of times _encode is called private $_calls; // stores latitude value from last _encode call private $_lastLat; // stores longitude value from last _encode call private $_lastLon; // public accessors public function get_encoded() { // set defaults $this->_calls = 0; $this->_lastLat = 0; $this->_lastLon = 0; // $encoded to store encoded points $encoded = ''; $args = func_get_args(); if ( is_array($args[0]) ) { while ( list($k, $arg) = each($args) ) $encoded .= $this->_encode($arg[0]) . $this->_encode($arg[1]); } else { $cnt = count($args); if ( !$cnt ) return false; $i = 0; while ( $i < $cnt ) $encoded .= $this->_encode($args[$i++]); } return $encoded; } public function get_decoded($str) { $points = array(); $lat = 0; $lon = 0; while (strlen($str)) { $lat += $this->_decode($str); $lon += $this->_decode($str); $points[] = array($lat * 1e-5, $lon * 1e-5); } return $points; } // private private function _encode($dec) { $dec = round($dec * 1e5, 0); if ( !($this->_calls % 2) ) { //lon if ( $this->_calls >= 2 ) $ndec = $dec - $this->_lastLon; $this->_lastLon = $dec; } else { //lat if ( $this->_calls >= 2 ) $ndec = $dec - $this->_lastLat; $this->_lastLat = $dec; } $dec = isset($ndec) ? $ndec : $dec; $is_neg = stristr($dec, '-'); $dec <<= 1; // invert bits if negative if ( $is_neg ) $dec = (~$dec); //0 pad to 32 bits $dec = str_pad(sprintf('%b', $dec), 30, '0', STR_PAD_LEFT); // chunk into 5 char strings and reverse $dec = array_reverse(str_split($dec, 5)); // or with 0x20 except last one ( add 63 to each and convert to ascii ) $c = count($dec); for ( $i = 0; $i < $c; ++$i ) $dec[$i] = (isset($dec[$i+1]) && $dec[$i+1] & 31) ? ((bindec($dec[$i]) | 32) + 63) : (((bindec($dec[$i])) > 0) ? bindec($dec[$i]) + 63 : ''); // set times called $this->_calls++; return vsprintf('%c%c%c%c%c%c', $dec); } private function _decode(&$str) { $shift = 0; $result = 0; $i = 0; do { // while ascii($str[$i++]) > ascii([space] " ") $b = ord($str[$i++]) - 63; $result |= ($b & 0x1f) << $shift; $shift += 5; } while ($b >= 0x20); $str = substr($str, $i); return (($result & 1) ? ~($result >> 1) : ($result >> 1)); } } ?>
  20. Ahh, I didn't think of that, cheers, will keep that in mind.
  21. SELECT media, COUNT(*) AS customer_count FROM customers GROUP BY media
  22. That's a very good question Because I'm an idiot, I'm sure that there was some misguided explanation I had in my head for it at the time, but looking at it, the only reason I can think of is because I'm too lazy to write getInstance() lol
  23. It's AJAX polling which is pull technology, basically the client sends requests to the server every x seconds, if the server responds with data, the data is processed and the DOM is manipulated accordingly. There are two types of polling, short polling and long polling. In short polling, the client sends a request, the server processes the request, outputs a response and the client handles the response accordingly, then after x seconds another request is sent. In long polling, the client sends a request, the server queries the database, if a result is found, the response is sent, otherwise the server continues querying until data is found and a request is sent, or a certain time period has expired, the response is sent to the client, and the client (usually immediately repeats the process). http://boardreader.com/thread/Short_polling_vs_Long_polling_for_real_t_5ft4kX2ri92.html There's a relatively new implementation of server-side javascript called node.js, which has a web-socket library called socketIO which can be used to push data to the client.
  24. Until participating and reading this topic, I had though the following code was perfectly fine. I don't claim to even be good at OOP or application design, although I would like to be lol Anyway, the only functionality regarding google maps polylines I could think of in PHP, was encoding and decoding them, so I placed them in a static class: <?php /* -- Polyline.class.php @return string (encoded lat/lng) - polyline::getEncoded(-2.5675, 2.5456); @return string (encoded lat/lng's) - polyline::getEncoded(array(-2.5675, 2.5456), array(-2.5675, 2.5456)); @return string (encoded lat/lng's) - polyline::getEncoded(-2.5675, 2.5456, -2.5675, 2.5456); @return array (decoded array(lat, lng)'s) - polyline::getDecoded('zmtn_?_epn_?zmtn_?_epn_?zmtn_?_epn_?'); */ class Polyline { private static $_calls = 0; private static $_lastLat = 0; private static $_lastLon = 0; // public accessors public static function get_encoded() { // $encoded to store encoded points $encoded = ''; $args = func_get_args(); if ( is_array($args[0]) ) { while ( list($k, $arg) = each($args) ) $encoded .= self::_encode($arg[0]) . self::_encode($arg[1]); } else { $cnt = count($args); if ( !$cnt ) return false; $i = 0; while ( $i < $cnt ) $encoded .= self::_encode($args[$i++]); } self::$_calls = 0; self::$_lastLat = 0; self::$_lastLon = 0; return $encoded; } public static function get_decoded($str) { $points = array(); $lat = 0; $lon = 0; while (strlen($str)) { $lat += self::_decode($str); $lon += self::_decode($str); $points[] = array($lat * 1e-5, $lon * 1e-5); } return $points; } // private private static function _encode($dec) { $dec = round($dec * 1e5, 0); if ( !(self::$_calls % 2) ) { //lon if ( self::$_calls >= 2 ) $ndec = $dec - self::$_lastLon; self::$_lastLon = $dec; } else { //lat if ( self::$_calls >= 2 ) $ndec = $dec - self::$_lastLat; self::$_lastLat = $dec; } $dec = isset($ndec) ? $ndec : $dec; $is_neg = stristr($dec, '-'); $dec <<= 1; // invert bits if negative if ( $is_neg ) $dec = (~$dec); //0 pad to 32 bits $dec = str_pad(sprintf('%b', $dec), 30, '0', STR_PAD_LEFT); // chunk into 5 char strings and reverse $dec = array_reverse(str_split($dec, 5)); // or with 0x20 except last one ( add 63 to each and convert to ascii ) $c = count($dec); for ( $i = 0; $i < $c; ++$i ) $dec[$i] = (isset($dec[$i+1]) && $dec[$i+1] & 31) ? ((bindec($dec[$i]) | 32) + 63) : (((bindec($dec[$i])) > 0) ? bindec($dec[$i]) + 63 : ''); // set times called self::$_calls++; return vsprintf('%c%c%c%c%c%c', $dec); } private static function _decode(&$str) { $shift = 0; $result = 0; $i = 0; do { // while ascii($str[$i++]) > ascii([space] " ") $b = ord($str[$i++]) - 63; $result |= ($b & 0x1f) << $shift; $shift += 5; } while ($b >= 0x20); $str = substr($str, $i); return (($result & 1) ? ~($result >> 1) : ($result >> 1)); } private function __construct() {} private function __clone() {} } ?> not that it matters much, since the rest of the application in which this class resides went to design shit, but; is this bad practice in your opinion?
  25. version > PHP 5.3 $array = array_filter($array, function($var) { return !($var % 2); }); version < PHP5.3 $array = array_filter($array, create_function('$var', 'return !($var % 2);')); Unless you mean odd one out as opposed to odd number? I just assumed not because in sequence 52, 51 the next would be 50 but you stated you wanted first and last (both 52)
×
×
  • 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.