Jump to content

Andy-H

Members
  • Posts

    2,000
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Andy-H

  1. I don't get it....

     

     

    You either get it or pussy.

     

    var protect:Boolean
    
    if (protect == false && 8==D)
    {
       knockedUp(); 
    }
    

    lol, I know, my girl hasn't put out in a while

  2.  

    <?php
    //If form is submitted, call the function and save all data into the array $_SESSION['form'] 
    if($_POST['submit'] == "Buy"){ unset($_POST['submit']); setSessionVars(); } 
    
    function setSessionVars() {
       if ( !isset($_SESSION['cart']) ) $_SESSION['cart'] = array();
       $_SESSION['cart'] = array_merge($_SESSION['cart'], $_POST);
       echo <<<HTML
       <table>
          <tr>
             <td><img src="images/{$item['item']}.jpg" /></td>
             <td>{$item['item']}</td>
             <td><input type="text" name="value" value="1" maxlength="30" /><input type="submit" name="puchasednum" value="Update This One Item" /></td>
          </tr>
       </table>
    HTML;
    }
    ?>
    
    

  3. $q="SELECT cb_video_categories.category_name,  cb_video_categories.cb_video FROM cb_video_categories, cb_video WHERE REPLACE(cb_video.category, '#', '') = cb_video_categories.category_id";

     

     

     

    Should probably just run:

     

     

    UPDATE cb_video SET category = REPLACE(category, '#', '');
    

     

     

    in phpmyadmin to replace all #'s and change the type to integer as programming languages handle integers much faster.

  4. What Thorpe is saying is that having two or more elements with the same ID is against W3C standards, use classes instead.

     

     

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
       <head>
          <title>Test</title>
          <!-- META //-->
          <meta name="description" content="" >
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
          <!-- JQUERY //-->
          <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
          <script type="text/javascript">
          <!--
             $(document).ready(function() {
                $('[class^="d_"]').bind({
                   'mouseenter' : function() {
                      $('.'+ $(this).attr('class')).css({
                         color      : '#f00',
                         fontWeight : 'bold'
                      });
                   },
                   'mouseleave' : function() {
                     $('.'+ $(this).attr('class')).css({
                         color      : '#000',
                         fontWeight : 'normal'
                      });
                   }
                });
             });
          //-->
          </script>
       </head>
       <body>
          <span class="d_22">Test</span>
          <span class="d_23">Test</span>
          <span class="d_22">Test</span>
          <span class="d_23">Test</span>
          <span class="d_22">Test</span>
          <span class="d_23">Test</span>
       </body>
    </html>
    

  5. If you're selecting the dates from a database just filter them in your query or PHP, it's easy:

     

     

    SELECT date FROM datetable WHERE DATEDIFF(date, NOW()) >= 0
    

     

     

    Also look into the jquery UI datepicker, you could replace the select box with this with jquery once the page has loaded, IMO it's a lot slicker than a drop-down

     

     

     

       // getdates.php
       // connect to mysql
       $query  = "SELECT date FROM datetable WHERE DATEDIFF(date, NOW()) >= 0";
       $result = mysql_query($query)or die(mysql_error());
       $dates  = array();
       while ( $row = mysql_fetch_row($result) )
          $dates[] = $row[0];
       echo json_encode($dates);
    

    $(document).ready(function() {
       var selector = 'select'; // select#id, select.class
       $(selector).replaceWith('<input type="text" id="date" >');
    
       var dates = [];
       $('#date').datepicker({
          dateFormat      : 'dd/mm/yy',
          minDate         : $.datepicker.formatDate('dd/mm/yy', new Date()),
          beforeShowDay   : function (date) {
             if ( typeof dates == 'undefined' )
             {
                $.ajax({
                   async   : false,
                   url     : 'http://mysite.com/getdates.php',
                   dataType: 'json',
                   success : function(data) {
                      dates.push(data);
                   }
                });
             }
             $.each(dates, function() {
                if ( date === new Date(this) )
                   return [true, ''];
             });
             return [false, ''];
          }
       });
    });
    

  6. I'm writing a sort of fake tracking unit in nodeJS, it basically selects a random location, limits it to within some bounds, then I plan to inset the data into a database on around 30 second intervals, it's for a real-time demo of our works tracking system, however, if the latlngs don't happen to land on a road, the directions API returns an empty route, anyone know if there's a way to auto-correct the start / destination of a route?

     

     

    Thanks

     

     

    // directions/directions.js

    
    var http       = require('http'), 
        latlng     = require('./latlng'),
        Polyline   = require('./polyline');
    
    
    var Directions = function(origin, destination, bounds) {
       // validate origin / destination
       origin      = latlng.parse(origin);
       destination = latlng.parse(destination);
       
       // validate bounds
       if ( typeof bounds == 'string' )
          this.bounds = latlng.convertBounds(bounds);
       this.bounds.NW = latlng.parse(this.bounds.NW);
       this.bounds.SE = latlng.parse(this.bounds.SE);
       if ( !latlng.parse(this.bounds.NW) || !latlng.parse(this.bounds.SE) )
          throw 'Invalid latitude / longitude supplied in bounds';
       if ( !origin )
          throw 'Invalid latlng supplied as origin';
       if ( !destination )
          throw 'Invalid latlng supplied as destination';
    
    
       origin      = latlng.restrictToBounds(origin, this.bounds);
       destination = latlng.restrictToBounds(destination, this.bounds);
       
       /** SET DESTINATION START / END POINT */
       this.origin      = [ origin.lat,      origin.lng ];
       this.destination = [ destination.lat, destination.lng ];
    
    
       /** GET DIRECTIONS / LAT LNG's */
       this.get         = function(callBack) {
             _requestDirections(this.origin, this.destination, callBack);
       };
       /** MILES PER SECOND TO MILES PER HOUR CONVERSION */
       var MPS2MPH      = 2.23693629;
       
       /** OPTIONS FOR HTTP REQUEST */
       var opts = {
          host : 'maps.googleapis.com',
          path : '/maps/api/directions/json?origin={origin}&destination={destination}&sensor=false',
          port : 80
       };
       
       /** REQUEST DIRECTIONS API */
       var _requestDirections = function(origin, destination, callBack) {
          // replace origin and destination
          opts.path = opts.path.replace('{origin}',      origin.join(','));
          opts.path = opts.path.replace('{destination}', destination.join(','));
          // request google directions api
          http.request(opts, function(response) {
             response.data = [];
             // UTF-8 ENCODING
             response.setEncoding('utf8');
             // WHEN DATA CHUNCKS ARE RECIEVED APPEND TO RESPONSE.DATA
             response.on('data', function (data) {
                response.data.push(data);
             });
             // WHEN RESPONSE HAS COMPLETED, USE RESPONSE.DATA
             response.on('end', function(){
                var points = _parseDirections(JSON.parse(response.data.join('')).routes[0].legs[0].steps);
                if ( typeof callBack == 'function' )
                   callBack.call(null, points, JSON.parse(response.data.join('')).routes[0].overview_polyline, Polyline);
             });
          }).end();
       };
       
       /** PARSE DIRECTIONS INTO LAT, LNG, SPEED, BEARING, ALTITUDE */
       var _parseDirections = function(directions) {
          var k, direction;
          var points     = [];
          for ( k in directions )
          {
             direction          = {};
             direction.latlng   = directions[k].end_location;
             direction.speed    = ((directions[k].distance.value / directions[k].duration.value) * MPS2MPH);
             direction.bearing  = latlng.getBearing(directions[k].start_location, directions[k].end_location);
             direction.altitude = 0;
             direction.delay    = directions[k].duration.value;
             points.push(direction);
          }
          return points;
       };
    };
    module.exports.create = function(origin, destination, bounds) {
       return new Directions(origin, destination, bounds);
    };
    

     

     

    // directions/latlng.js

    
    /** CONVERTS NUMERIC DEGREES TO RADIANS */
    toRad = function(n) {
       return n * Math.PI / 180;
    }
    /** CONVERTS RADIANS TO NUMERIC (SIGNED) DEGREES */
    toDeg = function(n)
    {
       return n * 180 / Math.PI;
    }
    module.exports.getBearing = function(origin, destination) {
       var lat   = [ origin.lat, destination.lat ];
       var lng   = [ origin.lng, destination.lng ];
       var R     = 6371; // km
       var dLat  = toRad(lat[1]-lat[0]);
       var dLon  = toRad(lng[1]-lng[0]);
       lat[0]    = toRad(lat[0]);
       lat[1]    = toRad(lat[1]);
       // calculate bearing
       var y = Math.sin(dLon)   * Math.cos(lat[1]);
       var x = Math.cos(lat[0]) * Math.sin(lat[1]) -
               Math.sin(lat[0]) * Math.cos(lat[1]) * Math.cos(dLon);
       var brng = toDeg(Math.atan2(y, x));
      return ( brng < 0 ) ? brng += 360 : brng;
    };
    module.exports.restrictToBounds = function(latlng, bounds) {
       if ( (typeof latlng.length).toLowerCase() == 'number' && latlng.length > 1 )
       {
          latlng.lat = latlng[0];
          latlng.lng = latlng[1];
       }
       if ( latlng.lat > bounds.NW.lat )
          latlng.lat = bounds.NW.lat;
       if ( latlng.lat < bounds.SE.lat )
          latlng.lat = bounds.SE.lat;
       if ( latlng.lng > bounds.NW.lng )
          latlng.lng = bounds.NW.lng;
       if ( latlng.lng < bounds.SE.lng )
          latlng.lng = bounds.SE.lng;
       return latlng;
    };
    module.exports.convertBounds = function(bound_name) {
       var bounds = {
          Nigeria : { 
             NW : [ 12.637242349197756, 3.927704592284158  ],
             SE : [ 7.871121752587033,  11.980683107909158 ]
          }
       };
       if ( !bounds.hasOwnProperty(bound_name) )
          return false;
       return bounds[bound_name];
    };
    module.exports.parse = function(latlng) {
       if ( (typeof latlng.length).toLowerCase() == 'number' && latlng.length > 1 )
       {
          latlng.lat = latlng[0];
          latlng.lng = latlng[1];
       }
       latlng.lat = parseFloat(latlng.lat);
       latlng.lng = parseFloat(latlng.lng);
       
       if ( typeof latlng.lat != 'number' || typeof latlng.lng != 'number' )
          return false;
       if ( latlng.lat < -90 || latlng.lat > 90 )
          return false;
       if ( latlng.lng < -180 || latlng.lng > 180 )
          return false;
       return latlng;
    };
    

    // directions/polyline.js

    
    var Polyline = (function() {
       return {
          decode : function(polyline) {
             var pts   = [];
             var lat      = 0;
             var lng      = 0;
             while ( polyline.points.length )
             {
                lat += _decode(polyline);
                lng += _decode(polyline);
                pts.push({
                   'lat' : (lat * 1e-5),
                   'lng' : (lng * 1e-5)
                });
             }
             return pts;
          }
       };
       function _decode(polyline) {
          var shift  = 0, 
              result = 0, 
              i      = 0,
              b;
          do { // while ascii(polyline['polyline']) > ascii([space] " ")
             b       = polyline.points.charCodeAt(i++) - 63;
             result |= (b & 0x1f) << shift;
             shift  += 5;
          } while ( b >= 0x20 );
          polyline.points = polyline.points.substr(i);
          return ((result & 1) ? ~(result >> 1) : (result >> 1));
       };
    })();
    module.exports = Polyline;
    

     

     

    // test.js

    
    var start = [ 9.7, 8.4 ];
    var end   = [ 9.8, 8.1 ];
    
    
    var directions = require('./directions/directions').create(start, end, 'Nigeria');
    
    
    directions.get(function(directions, polyline, decoder) {
       var decoded = decoder.decode(polyline);
       console.log(polyline);
    });
    

     

     

    Just in-case anyone's interested.

     

     

    Thanks for any help.

  7. aaah I guess chrome doesn't have it.  I did find it in FireFox...pretty cool

     

     

    +1 for Chrome here, and you can get addons with Chrome, and the developer console (Ctrl+Shift+J) is pretty much the same as firebug from where I'm standing. IE sucks donkey boll0ks but google have developed a plug-in called chrome frame, it's a 1 click install, activated via a meta tag and identified via the user agent string

     

     

    <meta http-equiv="X-UA-Compatible" content="chrome=1" > 
    

     

     

    Simple as that, rounded corners, proper opacity and V8 engine in IE.

  8. As we're into the 'Green' era of recycling, I've used this code on practically every site I've worked on to display my HTML

     

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
      <TITLE><?php echo $title; ?></TITLE>
      <META NAME="Generator" CONTENT="*******">
      <META NAME="Author" CONTENT="**********">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
      <?php echo $redirect; ?>
    
    <script type="text/javascript" src="myScripts.js"></script>
    
    <!-- a few page styles-->
    
    <link rel="mystyles.css" type = css/text>
    
    </HEAD>
    
    <BODY>
      <div id="wrapper">
      <div id="banner">
      <?php echo $banner; ?>  <>
      <  <div id="content">
      
       <?php echo $output; ?>
       
       
       <>
       <>
    </BODY>
    </HTML>
    
    

     

    As you can see, I can simply do my processing and then include this file with all / some of the variables set.

     

    I've got another couple I include if I need a 2 column or 3 column display

     

     

    Seriously? 4.0 transitional and block-caps tags and attributes?

     

    /?EDIT

     

    To expand, if you're looking to promote re-usable future-proof code, look into HTML 4.01 strict (/best practices)

     

    Some of this includes a space before the closing > of an un-closed tag:

     

    <!-- META //-->
    <meta name="description" content="Secure login" >
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
    <!-- LINKS AND SCRIPTS //-->
    <link rel="stylesheet" href="css/login.css" type="text/css" >
    

    this way, if you ever need to switch to XHTML, search and replace " >", " />"

     

    Also, HTML 4.01 strict is the closest version to HTML 5, so is likely to most resemble it, using this with best practices should make the switch to HTML 5 a little easier.

  9. The problem is that on the most part, people think, "What can I learn from you?" as opposed to "What can we learn from each other?" and when you post a topic like this; it tells people that you want to learn and gives them the impression that you don't know your way around PHP much. Everyone's had that annoying noob that flashes the orange tab at you on windows live every 10 seconds with another 30 lines of code followed by "can you fix this for me?!!!".

     

     

    I've been looking into PHP groups recently, I think me any my boss are going to go to the PHP North West (PHPNW) meetup on April 3rd, I've been told that they have a speaker on who has contributed to the PHP source, should be good.

     

     

    Maybe something like that would be good for you? Just search

    "PHP group " {name of your town/city}

    in google and then look on freenode for their IRC channel.

     

     

    Also there's already a large community out there to learn from, look at source code of open source projects on git hub or source forge, maybe even contribute to a project (remember, you're never under-qualified to work for free).

  10. Hi, I am writing some fleet tracking software at work and I want to add a feature that uses the google maps directions API but we are behind a login, we are purchasing a google maps licence but the directions API up's the cost by 100%, and we don't have enough customers to warrant that ATM. I was just wondering if anyone knew of a free directions API, or if I could get around the google licence, like make a PHP page that takes postcodes, makes a google API request and the outputs JSON, putting that in front of the login and then interfacing with that? Anyone know if this would be legit?

  11. % %blow

    %blow: No such job.

     

    Haha, I like that one. :D

     

     

    lol yeah, I've been with my girlfriend for just over a year so I've been familiar with that one for a while.

     

     

    @thorpe lol with a name like that, who needs a nickname? Have you seen Mike Hunt lately?

×
×
  • 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.