Searching for a location in the database by latitude/longitude.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rocky86
    New Member
    • Jun 2007
    • 93

    #31
    hi thx for the reply just wanted to noe what does this $_REQUEST do?

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #32
      tighter code

      Originally posted by Rocky86
      hi thx for the reply just wanted to noe what does this $_REQUEST do?
      In PHP you can use the GET or POST methods to pass values between pages. If you use a form with the post method then $_POST can be used to retreived the value, if use a form with the get method then the values can be retreived fro the query strng using $_GET. $_REQUEST will handle both of them and $_COOKIE.

      Personally I think it's clearer to use the one that corresponds with where the dat is coming from.

      For a more detailed description take a look at the W3Schools tutorial.

      One further change I would make, that I have just thought of:
      [PHP]

      if(isset($_GET['postal'])) // assuemd the value is on the URL, otherwise use $_POST
      {
      $postal = substr($_GET['postal'],0,2);// get the first two characters
      $qry = 'SELECT startlat, endlat, startlng, endlng FROM districts WHERE districtno = $postal');
      $results=mysql_ query($qry);
      }
      else
      {
      // you can add error trapping here if you want, or some alternative if the variable is not available.
      }
      [/PHP]

      nathj
      Last edited by nathj; Jul 3 '07, 07:38 AM. Reason: Adding some extra code

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #33
        Originally posted by Rocky86
        hi thx for the reply just wanted to noe what does this $_REQUEST do?
        Just don't use it. It's a bad habit to get into.

        Comment

        • Rocky86
          New Member
          • Jun 2007
          • 93

          #34
          hi ppl is me right now I am told to merge my code together and send it to actionscript any idea how to do it I am told to follow the example done by other ppl below is the code done by that person
          [PHP]
          $fetched=mysql_ query("SELECT * FROM location");
          while($row = mysql_fetch_arr ay($fetched))
          {
          $temp[]=$row;
          }
          foreach($temp as $extract)
          foreach($extrac t as $key=>$info)
          {
          if(!is_numeric( $key)) //somehow it returns number & name of key.so take 1. $coordinates[$key]=$info;
          foreach($coordi nates as $key=>$extract)
          $report=$report .$key."=".$extr act."&";
          echo $report;
          [/PHP]

          I don't understand what the code is doing and how to join them up
          below is the code I have now and is required to follow the code above to join them up and send it to actionscripts

          [PHP]
          $postal=substr( $_GET['postal'],0,2); //will return from 0 position 2 characters

          $resultpostal=m ysql_query("SEL ECT startlat,endlat ,startlng,endln g FROM districts
          WHERE districtno = $postal"); //get startlat,endlat ,startlng,endln g of employee location

          $resultname=mys ql_query("SELEC T uid,uname FROM location,distri cts
          WHERE location.lat < districts.start lat AND location.lat > districts.endla t AND location.lng < districts.start lng
          AND location.lng > districts.endln g");

          echo("resultpos tal" + "resultname ");
          }
          [/PHP]

          How do I join the code of mine together and send it to actionscript plss help me thx~

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #35
            Originally posted by volectricity
            Just don't use it [$_REQUEST]. It's a bad habit to get into.
            You'll have to explain that one to me. I use it all the time; I use $_SESSION when I really care about where the data comes from....

            Comment

            • Rocky86
              New Member
              • Jun 2007
              • 93

              #36
              Any ppl can help with my problem?

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #37
                Heya, Rocky.

                Tell whoever gave you that example code that next time, he should use mysql_fetch_ass oc() instead of mysql_fetch_arr ay()

                How are you sending the results to actionscript? Do you want to output an XML-formatted document for your Flash object to parse? Do you want to pass the variables as arguments in the query string? Do you want your script to output the actionscript itself?

                Comment

                • Rocky86
                  New Member
                  • Jun 2007
                  • 93

                  #38
                  Originally posted by pbmods
                  Heya, Rocky.

                  Tell whoever gave you that example code that next time, he should use mysql_fetch_ass oc() instead of mysql_fetch_arr ay()

                  How are you sending the results to actionscript? Do you want to output an XML-formatted document for your Flash object to parse? Do you want to pass the variables as arguments in the query string? Do you want your script to output the actionscript itself?
                  Hi what I want is pass the variables as arguments in the query string

                  Comment

                  • nathj
                    Recognized Expert Contributor
                    • May 2007
                    • 937

                    #39
                    Originally posted by Rocky86
                    Hi what I want is pass the variables as arguments in the query string
                    To pass the variables in the query string on PHP simply add them on the end of the url:


                    Then on index.php the following code will get that value for you:
                    [CODE=php]
                    <?php
                    if (isset($_GET['pageId']))
                    {
                    $lnPageID = $_GET['pageId'];
                    //use the variable however you want
                    }
                    else
                    {
                    echo 'The query string was not set properly';
                    // or some other form of exception code
                    }
                    ?>
                    [/CODE]

                    If you wish to pass the values from a form to another page in the query string this is done by setting the form action to 'get'. However, it is more advisable to use 'post' in a form situation. Then the in the code above you would replace $_GET with $_POST.

                    You can use $_REQUEST for either of these but it is not advisable as you have no idea then when reading the code where the data came from. Using the more specific $_POST or $_GET enables you to tell where the data came from. It makes life a lot easier for you now and in the future.

                    Alternatively you may wish to use $_SESSION. There are may discussions on this on this forum. But check out the manual for the basics

                    I hope this helped.
                    Cheers
                    nathj
                    Last edited by nathj; Jul 9 '07, 07:58 AM. Reason: Adding extra comment

                    Comment

                    • Rocky86
                      New Member
                      • Jun 2007
                      • 93

                      #40
                      hi I manage to come out with my php code pls help check iszit correct
                      [PHP]
                      <?php
                      $coordinates=ar ray();
                      $report="";
                      $temp="";


                      $sqlconnect=mys ql_connect("loc alhost","hyperi an_track","gsmt rack");
                      if(!$sqlconnect )
                      die(mysql_error ());
                      mysql_select_db ("hyperian_trac k", $sqlconnect);


                      if(isset($_GET['postal'])) //check if is true
                      {

                      $postal=substr( $_GET['postal'],0,2); //will return from 0 position 2 characters

                      $resultpostal=m ysql_query("SEL ECT startlat,endlat ,startlng,endln g FROM districts
                      WHERE districtno = $postal"); //get startlat,endlat ,startlng,endln g of employee location

                      while($row = mysql_fetch_arr ay($resultposta l))
                      {
                      $temp[]=$row; // store each record in an array
                      }

                      foreach($temp as $extract)
                      foreach($extrac t as $key=>$info)
                      {
                      if(!is_numeric( $key))
                      $coordinates[$key]=$info; //detect if what you extracted from $temp is not numeric and store it in $coordinates
                      }

                      foreach($coordi nates as $key=>$extract) // store the values in the $coordinates and $extract into $report and display them in the screen....

                      $report=$report .$key."=".$extr act."&";


                      echo $report;


                      $resultname=mys ql_query("SELEC T uid,uname FROM location,distri cts
                      WHERE location.lat < districts.start lat AND location.lat > districts.endla t AND location.lng < districts.start lng
                      AND location.lng > districts.endln g");

                      while($row = mysql_fetch_arr ay($resultname) )
                      {
                      $temp[]=$row;
                      }

                      foreach($temp as $extract)
                      foreach($extrac t as $key=>$info)
                      {
                      if(!is_numeric( $key))
                      $coordinates[$key]=$info;
                      }

                      foreach($coordi nates as $key=>$extract)
                      $report=$report .$key."=".$extr act."&";


                      echo $report;

                      }//end of if loops

                      else
                      {
                      echo ("error");
                      }


                      mysql_close($co n);

                      [/PHP]

                      My Objective is:
                      In php join them up then send it actionscript

                      actionscript will seperate them out

                      Comment

                      • nathj
                        Recognized Expert Contributor
                        • May 2007
                        • 937

                        #41
                        Hi Rocky86,

                        I have read over this quickly and it looks okay, there is lots of array parsing going on. The best way to find out if it is working or not is to run the code. Then work through any issues that you have.

                        If you come up against anything you can't resolve then post the specifics. I'll do what I can to help out.

                        Cheers
                        nathj

                        Comment

                        • Rocky86
                          New Member
                          • Jun 2007
                          • 93

                          #42
                          Originally posted by nathj
                          Hi Rocky86,

                          I have read over this quickly and it looks okay, there is lots of array parsing going on. The best way to find out if it is working or not is to run the code. Then work through any issues that you have.

                          If you come up against anything you can't resolve then post the specifics. I'll do what I can to help out.

                          Cheers
                          nathj
                          hihi nathj thx for taking the effort to help me out man but do you know how do I send this php code to actionscripts and use the actionscript to separate the code out?

                          do I need to create function on actionscript to take in the php code?

                          Comment

                          • nathj
                            Recognized Expert Contributor
                            • May 2007
                            • 937

                            #43
                            Originally posted by Rocky86
                            hihi nathj thx for taking the effort to help me out man but do you know how do I send this php code to actionscripts and use the actionscript to separate the code out?

                            do I need to create function on actionscript to take in the php code?
                            Unfortunatley thats where my ability dies on this one. I have never done this and am not even sure what it is. I assume its Flash we're talking about? I have only ever done really basic stuff in flash - like image transitions.

                            Sorry I can't be any more help on this.

                            Cheers
                            nathj

                            Comment

                            • Rocky86
                              New Member
                              • Jun 2007
                              • 93

                              #44
                              Originally posted by nathj
                              Unfortunatley thats where my ability dies on this one. I have never done this and am not even sure what it is. I assume its Flash we're talking about? I have only ever done really basic stuff in flash - like image transitions.

                              Sorry I can't be any more help on this.

                              Cheers
                              nathj
                              Oh anyway nathj you have been a great help thx alot!!

                              Comment

                              • pbmods
                                Recognized Expert Expert
                                • Apr 2007
                                • 5821

                                #45
                                Heya, Rocky.

                                The way I would do it would be to load the file in your Actionscript.

                                Comment

                                Working...