roldahayes Posted September 16, 2008 Share Posted September 16, 2008 Hi There, I have been trying to implement like this into a website. http://www.acmultimedia.co.uk/blog/article.php?blogID=59 I have ran the SQL file and set the data base up but am completly lost with what to do next! Do I have ALL the code in the tutorial in the page that the form connects to?? Completly lost! Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/ Share on other sites More sharing options...
drisate Posted September 16, 2008 Share Posted September 16, 2008 show us the code you have so fare Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-642867 Share on other sites More sharing options...
roldahayes Posted September 16, 2008 Author Share Posted September 16, 2008 well I dont really have anything yet - just the database. Ive look at all the code snippets on the example site but not sure how to implement them into the relivant pages Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-642914 Share on other sites More sharing options...
scottybwoy Posted September 16, 2008 Share Posted September 16, 2008 Do you know any php or html as some knowledge will be know to help you do this. First you need to set up a simple form to put in the post code you want to compare. Then you need that to send the data to your script file using POST/GET. You will need to specify, what other post code you want to compare it. All the code that was provided in that blog can sit in one file. Try that first, then ask if you need more help. Good Luck Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-642942 Share on other sites More sharing options...
roldahayes Posted September 16, 2008 Author Share Posted September 16, 2008 Thanks, I'm fine with HTML and not too bad with PHP. I'll set the pages up and see what happens... Watch this space... Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-642947 Share on other sites More sharing options...
roldahayes Posted September 16, 2008 Author Share Posted September 16, 2008 Ok, heres the form <form name="locator" method="get" action="postcode.php" id="storeFinder"> <label for="p" class="hidden">Post code</label> <input type="text" name="p" id="p" value="" maxlength="8" class="storeLocatorText" /> <input type="submit" class="buttonStandard" value="Search" style="margin-left:5px;float:left;width:75px;" /> </form> and postcode.php is <?php #Convert the post code to upper case and trim the variable $postcode = strtoupper(trim($postcode)); #Remove any spaces $postcode = str_replace(" ","",$postcode); #Trim the last 3 characters off the end $postcode_first = substr($postcode,0,strlen($postcode)-3); "SELECT * FROM tblhwz_postcodes WHERE fldPostCode = '$postcode_first' LIMIT 1"; Does the post code exist? if ($myrow["fldPostCode"] != ""){ #Assign variables $code1_lat = $myrow["fldLatitude"]; $code1_long = $myrow["fldLongitude"]; }else{ #post code not found } function getDistance($lat1, $long1, $lat2, $long2){ #$earth = 6371; #km change accordingly $earth = 3960; #miles #Point 1 cords $lat1 = deg2rad($lat1); $long1= deg2rad($long1); #Point 2 cords $lat2 = deg2rad($lat2); $long2= deg2rad($long2); #Haversine Formula $dlong=$long2-$long1; $dlat=$lat2-$lat1; $sinlat=sin($dlat/2); $sinlong=sin($dlong/2); $a=($sinlat*$sinlat)+cos($lat1)*cos($lat2)*($sinlong*$sinlong); $c=2*asin(min(1,sqrt($a))); $d=round($earth*$c); return $d; } #Returns the distance in miles $distance = getDistance($code1_lat, $code1_long, $code2_lat, $code2_long); ?> just returns a blank page at the moment though... im not entirley sure the script is set up right for the field names in the database...? database structure is CREATE TABLE `hwz_postcodes` ( `outcode` varchar(5) NOT NULL default '', `x` int(11) NOT NULL default '0', `y` int(11) NOT NULL default '0', `latitude` int(11) NOT NULL default '0', `longitude` int(11) NOT NULL default '0', PRIMARY KEY (`outcode`), KEY `x` (`x`,`y`) ) TYPE=MyISAM COMMENT='stores hwz postcode data and coords'; Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-642962 Share on other sites More sharing options...
roldahayes Posted September 16, 2008 Author Share Posted September 16, 2008 yep - think its def a problem with the data base... Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-643099 Share on other sites More sharing options...
scottybwoy Posted September 18, 2008 Share Posted September 18, 2008 Firstly you need to convert your Get Data to a $var called $postcode so in your postcodes.php page put : $postcode = $_GET['p']; At the top of your page. Then you will need to actually connect to your database via mysql_connect()... Look it up on the php.net manual. In fact look up how to do basic queries in mysql, there are a couple more functions you will need to use to make your statement work (mysql_query() & mysql_result()). And you statement is written wrong. Change : "SELECT * FROM tblhwz_postcodes WHERE fldPostCode = '$postcode_first' LIMIT 1"; to $qry = mysql_query("SELECT * FROM tblhwz_postcodes WHERE fldPostCode = '" . $postcode_first . "' LIMIT 1"); Finally right at the bottom before ?> add something like : echo $distance; To present something to your page, otherwise it will remain blank as you say. The problem with your database is that your not actually connecting to it at all! I suggest going to the w3schools website to look up about GET and POST data, and see the php manual on mysql functions. Good Luck. Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-644581 Share on other sites More sharing options...
roldahayes Posted October 14, 2008 Author Share Posted October 14, 2008 Ok, getting a bit further with it (I hope!) search.php <form name="form1" method="post" action="postcode_search.php"> <label></label> <table width="400" border="0" cellspacing="3" cellpadding="3"> <tr> <td><label><strong>Post Code: </strong></label></td> <td><input type="text" name="postcode" id="postcode"></td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="search" id="search.php" value="search"> </label></td> </tr> </table> <p> </p> <p> <label></label> </p> <p> <label></label> </p> <p> <label></label> </p> </form> postcode_search.php <?php $postcode = $_GET['p']; ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> <?php $hostname = "localhost"; $database = "viewmykitchen1"; $username = "test"; $password = "test"; $database = mysql_pconnect($hostname, $username, $password) or die(mysql_error()); ?> <?php #Convert the post code to upper case and trim the variable $postcode = strtoupper(trim($postcode)); #Remove any spaces $postcode = str_replace(" ","",$postcode); #Trim the last 3 characters off the end $postcode_first = substr($postcode,0,strlen($postcode)-3); $postcode =($_POST['postcode'])); $qry = mysql_query("SELECT * FROM tblhwz_postcodes WHERE fldPostCode = '" . $postcode_first . "' LIMIT 1"); ?> <?php Does the post code exist? if ($myrow["fldpostcode"] != ""){ #Assign variables $code1_lat = $myrow["fldlatitude"]; $code1_long = $myrow["fldlongitude"]; }else{ #post code not found } ?> <?php function getDistance($lat1, $long1, $lat2, $long2){ #$earth = 6371; #km change accordingly $earth = 3960; #miles #Point 1 cords $lat1 = deg2rad($lat1); $long1= deg2rad($long1); #Point 2 cords $lat2 = deg2rad($lat2); $long2= deg2rad($long2); #Haversine Formula $dlong=$long2-$long1; $dlat=$lat2-$lat1; $sinlat=sin($dlat/2); $sinlong=sin($dlong/2); $a=($sinlat*$sinlat)+cos($lat1)*cos($lat2)*($sinlong*$sinlong); $c=2*asin(min(1,sqrt($a))); $d=round($earth*$c); return $d; } ?> <?php #Returns the distance in miles $distance = getDistance($code1_lat, $code1_long, $code2_lat, $code2_long); echo $distance; ?> Am I getting any further with this??? Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-665308 Share on other sites More sharing options...
revraz Posted October 14, 2008 Share Posted October 14, 2008 We don't know, are you? Is it displaying? Am I getting any further with this??? Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-665316 Share on other sites More sharing options...
roldahayes Posted October 14, 2008 Author Share Posted October 14, 2008 oh yeah, right, sorry! Err - no it's not! Quote Link to comment https://forums.phpfreaks.com/topic/124491-can-anyone-point-me-in-the-right-direction/#findComment-665432 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.