By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

How to convert php script to access

P: n/a
How can I convert the following script to be used in access?

<Html>
<head>
<title>Dealers</title>
</head>
<h5>List of Dealers Nearest to your Zip Code</h5><br><br>

<?
$errflag = false;
$conn = mysql_connect("localhost:3306","uid","pass");
mysql_select_db("tbcdealers");
$query = "select * from zipcode where Zipcode = '" . $txtZip . "'";
$result = mysql_query($query,$conn);
$row = mysql_fetch_row($result);
if ($row == false) {
$errflag = true;
$errmsg = "The Zip Code you entered is invalid";
echo "<blockquote>$errmgs</blockquote>";
}
else {
$lat1 = $row[3];
$long1 = $row[4];
}
if ($errflag == false){
$sql = "select zipcode.zipcode, sqrt(power(69.1*(zipcode.latitude - $lat1),2)+
power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) as dist,
$dealer.* from $dealer LEFT JOIN zipcode on " ;
$sql = $sql . " $dealer.zip = zipcode.zipcode where
sqrt(power(69.1*(zipcode.latitude - $lat1),2)+
power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) < " .
$cboDist ;
$result = mysql_query($sql,$conn);
$count = mysql_num_rows($result);
echo "<blockquote><table border=0>";
for ($i=0; $i < $count; $i++) {
echo "<tr><td>";
$row = mysql_fetch_row($result);
echo "<b>",$row[3],"</b><BR>" ;
echo $row[4],"<BR>" ;
if ($row[5] <> ""){
echo $row[5],"<BR>" ;
}
echo $row[6],"<BR>" ;
echo $row[7],"<BR>";
echo $row[8],"<BR>";
$dm = sprintf("%3.2f",$row[1]);
echo "Distance : $dm miles.<BR><BR>";
echo "</td></tr>";
}
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 17 Jul 2004 10:58:17 GMT, ga*****@aol.com (Galsaba) wrote:

By understanding what this script does and then completely re-writing
it in Access/VBA. There is no conversion tool.

-Tom.

How can I convert the following script to be used in access?

<Html>
<head>
<title>Dealers</title>
</head>
<h5>List of Dealers Nearest to your Zip Code</h5><br><br>

<?
$errflag = false;
$conn = mysql_connect("localhost:3306","uid","pass");
mysql_select_db("tbcdealers");
$query = "select * from zipcode where Zipcode = '" . $txtZip . "'";
$result = mysql_query($query,$conn);
$row = mysql_fetch_row($result);
if ($row == false) {
$errflag = true;
$errmsg = "The Zip Code you entered is invalid";
echo "<blockquote>$errmgs</blockquote>";
}
else {
$lat1 = $row[3];
$long1 = $row[4];
}
if ($errflag == false){
$sql = "select zipcode.zipcode, sqrt(power(69.1*(zipcode.latitude - $lat1),2)+
power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) as dist,
$dealer.* from $dealer LEFT JOIN zipcode on " ;
$sql = $sql . " $dealer.zip = zipcode.zipcode where
sqrt(power(69.1*(zipcode.latitude - $lat1),2)+
power(69.1*(zipcode.longitude-$long1)*cos(zipcode.latitude/57.3),2)) < " .
$cboDist ;
$result = mysql_query($sql,$conn);
$count = mysql_num_rows($result);
echo "<blockquote><table border=0>";
for ($i=0; $i < $count; $i++) {
echo "<tr><td>";
$row = mysql_fetch_row($result);
echo "<b>",$row[3],"</b><BR>" ;
echo $row[4],"<BR>" ;
if ($row[5] <> ""){
echo $row[5],"<BR>" ;
}
echo $row[6],"<BR>" ;
echo $row[7],"<BR>";
echo $row[8],"<BR>";
$dm = sprintf("%3.2f",$row[1]);
echo "Distance : $dm miles.<BR><BR>";
echo "</td></tr>";
}


Nov 13 '05 #2

P: n/a
ga*****@aol.com (Galsaba) wrote in
news:20***************************@mb-m25.aol.com:
How can I convert the following script to be used in access?


What do you mean "used in Access?"

Do you mean doing the same thing in an MDB running the program
Microsoft Access?

Or do you mean using an MDB file created with Access as the data
source for a web page?

If the latter, it's pretty simple -- you won't need to do anything
but change the method for opening the result set, using ODBC. It
could look something like this, assuming you've got an ODBC DSN
defined:

$db=odbc_pconnect("[DSN Name]","[UID]","[PW]");
$Dealers=odbc_exec($db,"select * from zipcode where Zipcode = '"
. $txtZip . "'");
[I don't know how you'd check to see if it returns no rows; my guess
is that you can test $Dealers somehow to find out if it's empty --
depends on what kind of object odbc_exec() returns]
while(odbc_fetch_row($Dealers)) {
[do whatever you want to do with each row]
}

(it also seems to me that you have a structural error in your
control structure: the part executed in if ($errflag == false){}
could just as easily be in the ELSE clause of the original IF
statement, and then you wouldn't need to bother with the $errflag)

(let me also suggest that you could save processing by simply
returning the dealers first; if none is returned *then* check the
zip code table to see if the zip code was invalid or not; that means
you'd have two hits against the back end only when an invalid zip
code was entered or only when no dealers were found)

If the former, it's substantially more complex and can't really be
answered, as it's not going to be at all the same thing.

I've said it a million times, but I'll say it again: I really,
really, really wish people would distinguish Access from Jet: Jet is
the database engine, Access is the development tool and desktop
database program that uses Jet as its native database format. When
you're connecting to an MDB file from anything other than Access
itself, YOU'RE NOT USING ACCESS! You're only using Jet.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.