#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    I have had some success
    I have searched around and got a distance calulator working, using zipcode to long/lat. Well I have a member query form, which works fine. It will return all rows matching search criteria. then I added the distance calcualtor, and everytime it went throught query the distance kept compounding.
    So I removed the while statement and it goes through once, returning only one result. which doesnt help.
    here is the source http://www.ultimatenetwork.net/ss1.phps

    or the cutnpate here
    <? $username = $HTTP_COOKIE_VARS[ "username"] ?>
    <html>
    <body>
    <h1>These are your results <? echo $username ?></h1>
    <?php
    mysql_connect (localhost, usr, pswd);
    mysql_select_db (db);
    print mysql_error();

    /* the search criteria from search for */

    if ($susername == "")
    {$susername = '%';}
    if ($memage == "")
    {$memage = '%';}
    print mysql_error();

    $result = mysql_query ( "SELECT * FROM members
    WHERE username LIKE '$susername%'
    AND memsex LIKE '$memage%' ");

    /* retrieving the zip code from members table using username from
    * the cookie
    */

    $query0 = "select * from members where username = '$username' ";
    $result1 = mysql_query($query0);
    $row1 = mysql_fetch_array($result1);

    print mysql_error();

    /* retrieving zipcode from from row array and matching it to
    * the zipcode in zipcode table */

    $query1 = "select * from zipcode where zipcode = '$row1[zip]' ";
    $result2 = mysql_query($query1);
    $row2 = mysql_fetch_array($result2);

    /* part of distance cal */

    $pi = 3.1415926;
    $rad = doubleval($pi/180.0);

    /* starts print the results table, they have been cut down to ease the eyes */

    print "<table border=2 cellpadding=0 cellspacing=0 width=75%>n";
    print "<tr><td width=17%>n";
    print "Users name";
    print "</td>";
    print "<td width=8%>n";
    print "Age";
    print "</td>";
    print "<td width=6%>n";
    /* this $row had a while statement in it, but the calculation compounded */

    $row = mysql_fetch_array($result);
    print "<tr><td width=17%>n";
    echo ( "<a href=result url");
    echo $row[ "username"];
    echo ">";
    print $row[ "username"];
    echo "</a>";
    print "</td>";
    print "<td width=6%>n";
    print $row[ "memage"];
    print "</td>";
    /* this is the user query selecting a new zip and getting the long and lat for every user returned */

    $query2 = "select * from zipcode where zipcode = '$row[zip]' ";
    $result3 = mysql_query($query2);
    $row3 = mysql_fetch_array($result3);

    include( "calc.php3");

    /* the calc.php3 file
    ----<?
    $row2[longitute] = doubleval($row2[longitute])*$rad;
    $row2[latitude] = doubleval($row2[latitude])*$rad;
    print mysql_error();
    $row3[longitute] = doubleval($row3[longitute])*$rad;
    $row3[latitude] = doubleval($row3[latitude])*$rad;
    print mysql_error();
    $theta = $row3[longitute] - $row2[longitute];
    $dist = acos(sin($row2[latitude]) * sin($row3[latitude]) + cos($row2[latitude]) * cos($row3[latitude]) * cos($theta));
    if ($dist < 0) { $dist += $pi; }
    $dist = $dist * 6371.2;
    $miles = doubleval($dist * 0.621);
    $inches = doubleval($miles*63360);
    $dist = sprintf( "%.2f",$dist);
    $miles = sprintf( "%.2f",$miles);
    $inches = sprintf( "%.2f",$inches);
    print mysql_error();
    ?>

    ----back to ss1.php3 */

    print mysql_error();
    print "<td width=6%>n";
    print $dist;
    print "</td></tr>";
    ?>
    </table>
    Click on the nickname to see the persons profile
    </body>
    </html>

    Thanks for the help to get it to loop for the users returned..

    Uga
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    how would I call the calculation if I made it a function with print $dist in the function. calcmap() ~calulations~ print $dist. Would the varibles from other querys on the page make it in to the function? or is a function a closed process ?
    Thanks for any help,

    Uga
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    Ok, I got it working and repeating all the results, using the calc as a function with globals set. However the distance is compounding, any way to reset the varibles on every cycle ?

    Uga
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    15
    Rep Power
    0
    Well I made the calc a function and put the print inside of it. Its still compounding.
    I tired unset, that didnt work... Help ..
    please?
    Uga

Similar Threads

  1. Special structure for sql query while loop?
    By Jhorra in forum PHP Development
    Replies: 4
    Last Post: February 3rd, 2004, 08:40 PM
  2. calculation in query ?
    By stojan in forum MySQL Help
    Replies: 1
    Last Post: January 14th, 2004, 04:08 PM
  3. Math functions in query?
    By jdcrack in forum MySQL Help
    Replies: 2
    Last Post: December 31st, 2003, 05:33 PM
  4. Syntax error in INSERT INTO query
    By Lee Miles in forum Visual Basic Programming
    Replies: 6
    Last Post: December 19th, 2003, 08:37 AM
  5. checkbox insert query
    By numb in forum PHP Development
    Replies: 11
    Last Post: December 15th, 2003, 12:10 PM

IMN logo majestic logo threadwatch logo seochat tools logo