khan kaka Posted October 20, 2006 Share Posted October 20, 2006 can some one explain to me how this code works or convert this code to dream weaver style.i want to be able to bind date and and apply rpeat reagion behaviour .this is the code:<?php//@ $mySQLConnection = mysql_connect("localhost", "ultratune", "u1tr@t00n3");@ $mySQLConnection = mysql_connect('localhost', 'root', '');mysql_select_db("ultratune");$postcode = 3174; /* zipcode */$suburb = @$_GET["suburb"]; $storename = @$_GET["storename"];$SearchDistance = 10; /* km */$EarthRadius = 6365;$pc = array();// if we are searching by city then get the suburbif (strlen($storename) != 0) { //echo "by storename"; $qry = "select postcode from stores where storename = '$storename' limit 1"; $recordSetStore = mysql_query($qry); if (mysql_num_rows($recordSetStore) > 0) { $result = mysql_fetch_array($recordSetStore); $pc[$result["state"]] = $result["postcode"]; } }else if (strlen($postcode) != 0 && strlen($suburb) != 0) { //echo "by city"; $qry = "select Min(postcode) as postcode, state from postcodes where city = '$suburb' group by state"; $recordSetPC = mysql_query($qry); if (mysql_num_rows($recordSetPC) > 0) { if (mysql_num_rows($recordSetPC) > 1) { for ($i = 0; $i < $toCount; $i++) { $currentRow = mysql_fetch_array($recordSetPC); $pc[$currentRow["state"]] = $currentRow["postcode"]; } } else { $result = mysql_fetch_array($recordSetPC); $pc[$result["state"]] = $result["postcode"]; } } }else if (strlen($postcode) == 0 && strlen($suburb) != 0) { //echo "by city 2"; $qry = "select Min(postcode) as postcode, state from postcodes where city = '$suburb' group by state"; $recordSetPC = mysql_query($qry); if (mysql_num_rows($recordSetPC) > 0) { if (mysql_num_rows($recordSetPC) > 1) { for ($i = 0; $i < mysql_num_rows($recordSetPC); $i++) { $currentRow = mysql_fetch_array($recordSetPC); $pc[$currentRow["state"]] = $currentRow["postcode"]; } } else { $result = mysql_fetch_array($recordSetPC); $pc[$result["state"]] = $result["postcode"]; } } }else if (strlen($postcode) != 0) { //echo "by postcode"; $qry = "select postcode,state from postcodes where postcode = '$postcode' limit 1"; $recordSetStore = mysql_query($qry); if (mysql_num_rows($recordSetStore) > 0) { $result = mysql_fetch_array($recordSetStore); $pc[$result["state"]] = $result["postcode"]; } }else { echo "nothing"; echo "<br>storename = " .strlen($storename); echo "<br>suburb = " .strlen($suburb); echo "<br>postcode = " .strlen($postcode); } function getLongAndLat($pcode) { $qry = "select longitude, latitude from postcodes where postcode = $pcode limit 1"; $recordSetLonLat = mysql_query($qry); $result = mysql_fetch_array($recordSetLonLat); return "<longitude>" .$result["longitude"] ."</longitude><latitude>" .abs($result["latitude"]) ."</latitude>"; }if (count($pc) > 0) { $xmlStr = "<stores>"; while ($item = each($pc) ) { $xmlStr = "$xmlStr<state name=\"" .$item["key"] ."\">"; $itemPostCode = $item["value"]; $CenterLonQry = mysql_query("select longitude from postcodes WHERE PostCode = $itemPostCode LIMIT 1"); $CenterLonRecord = mysql_fetch_array($CenterLonQry); $CenterLon = $CenterLonRecord[0]; $CenterLatQry = mysql_query("select latitude from postcodes WHERE PostCode = $itemPostCode LIMIT 1"); $CenterLatRecord = mysql_fetch_array($CenterLatQry); $CenterLat = $CenterLatRecord[0]; $postCodes = " SELECT DISTINCT postcodes.PostCode, MIN($EarthRadius * acos((XAxis * (cos(RADIANS($CenterLat)) * cos(RADIANS($CenterLon)))) + (YAxis * (cos(RADIANS($CenterLat)) * sin(RADIANS($CenterLon)))) +(ZAxis * sin(RADIANS($CenterLat))))) AS ProxDistance, stores.* FROM postcodes, stores WHERE ( $EarthRadius * acos( XAxis * (cos(RADIANS($CenterLat)) * cos(RADIANS($CenterLon))) + YAxis * (cos(RADIANS($CenterLat)) * sin(RADIANS($CenterLon))) + ZAxis * sin(RADIANS($CenterLat))) <= $SearchDistance OR postcodes.PostCode = $itemPostCode ) AND stores.PostCode = postcodes.PostCode GROUP BY postcodes.PostCode ORDER BY ProxDistance ASC "; $recordSet = mysql_query($postCodes); $records = mysql_num_rows($recordSet); $toCount = min(50, $records-1); for ($i = 0; $i <= $toCount; $i++) { $currentRow = mysql_fetch_array($recordSet); $thisLonLat = getLongAndLat($currentRow["Postcode"]); $xmlStr = "$xmlStr<location> <locationName>" .$currentRow["StoreName"] ."</locationName> <franchisee>" .$currentRow["Franchisee"] ."</franchisee> <manager>" .$currentRow["Manager"] ."</manager> <address1>" .$currentRow["Address1"] ."</address1> <address2>" .$currentRow["Address2"] ."</address2> <suburb>" .$currentRow["Suburb"] ."</suburb> <state>" .$currentRow["State"] ."</state> <postcode>" .$currentRow["Postcode"] ."</postcode> <phone>" .$currentRow["PhoneNumber"] ."</phone> <fax>" .$currentRow["FaxNumber"] ."</fax> <email>" .$currentRow["EmailAddress"] ."</email> <image>" .$currentRow["Image"] ."</image> " .$thisLonLat ." </location> "; } $xmlStr = "$xmlStr</state>"; // loop again } $xmlStr = "$xmlStr</stores>"; }else { $xmlStr = "<stores></stores>"; }echo "$xmlStr"; echo $currentRow["StoreName"];?> Quote Link to comment https://forums.phpfreaks.com/topic/24540-need-help-with-this-php-code-willing-to-pay/ Share on other sites More sharing options...
wildteen88 Posted October 29, 2006 Share Posted October 29, 2006 A repeat region is a query and a while loop. I would recommend you to lean how to code in PHP and MySQL and don't use Dreamweaver to code it for you.If you want someone to it for you then post in the PHP Freelancing forum instead. Quote Link to comment https://forums.phpfreaks.com/topic/24540-need-help-with-this-php-code-willing-to-pay/#findComment-116276 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.