Saturday, December 1, 2007

Google Maps Not Working in Internet Explorer, Operation Aborted

This has been bothering me for a while now. This is about the phpGoogleStoreLocator script that I have been working on integrating into a site the past few days. Just when everything was fine and seems to be working properly, it wouldn't function on Internet Explorer. Everytime I open it, it just crashes. I let other people try it and they experience the same thing.

So after googling around I found out that this problem usually occur when you have a script tag inside your tables. This was not the case on my part but I'll be sure to look out for this one. Apparently the solution to my problem is to put the map initialization code into a function say "loadMap()" and attach it to the body tag like this .

Other solutions to the problem if the the ones above still won't work for you are :

  1. Enclosing with a div tag where you want your map to appear. Something like this one : <div id=”map” style=”width: 400px; height: 400px”> and then make sure that all your javascripts are at the bottom of your document below the body tag. Thanks to Ryan.
  2. Moving the map function in the window.onload() handler. Thanks to Justin.
These solution will mostly work but if it still won't try to visit the Microsoft support site here.

Wednesday, November 28, 2007

Slow programming day...been traveling

I just arrived at my parents house today. I came here to visit them until the Christmas season. I've been traveling whole day so no programming for me today. Travel is 5 hours total which consists of 3.5 hours of land travel and 1.5 hours by plane :). I'm going rest for the rest of the day then I will continue programming tomorrow. I'll be back soon to post what I have done.

.... I miss my girlfriend already.. hehehe.

Sunday, November 25, 2007

Exporting mysql data to csv

Today I'm going to discuss the opposite of the previous post. Here it is :

/*some checking here like if the user is logged in, this is important in cases where we don't want other users to get hold of the data*/

//connect to the mysq;
define('host', 'localhost'); //Mysql Server name
define('database', 'dbname'); //Mysql Database name
define('user', 'dbuser'); //Mysql Username
define('password', 'dbpassword'); //Mysql Password
$dbtable = "dbtable";
$connection = mysql_connect(host,user,password);
$db = mysql_select_db(database,$connection);

$sql = mysql_query("select * from ".$dbtable.");

$fields = mysql_list_fields("yourdatabasename",$dbtable);
$columns = mysql_num_fields($fields);
$output = '';

// Put the name of all fields
for ($i = 0; $i < $columns; $i++)
{
$l=mysql_field_name($fields, $i);
$output .= '"'.$l.'",';
}

$output .="\n";

//we now put all values from table
while ($l = mysql_fetch_array($sql))
{
for ($i = 0; $i < $columns; $i++)
{
$output .='"'.$l["$i"].'",';
}

$output .="\n";
}

// Output to browser with appropriate mime type, you choose
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=yourcsvfile.csv");
echo $output;
exit;

?>

This script will prompt for a download for the csvfile named yourcsvfile.csv which contain all the columns and entries from the table dbtable.

Thursday, November 22, 2007

Importing a csv file to mysql

This is one of the things I did with my current project. It is about adding data on MySQL using a csv file and I thought I should share what I did.

First we need to have an html form that will ask for the file input. It will be something like this one:

[form action="import_csv.php" method="post" enctype="multipart/form-data"]
[input name="csv" type="file"]
[input name="filesubmit" value="Submit" type="submit"]
[/form]

Note: Replace "[" and "]" with "<" and ">" respectively. I did it like this because this blog won't allow attaching of html tags.

The enctype attribute is very important because it specifies to use "multipart/form-data" as content type for the form. This also means that the form requires a binary data like the file. The file input type specifies the input is looking for a file. This will appear as a text field with a browse button next to it.

Then we need our php script that will process the csv file and save the entries on the database.

//this is where the file is stored temporarily
$csvfile = $_FILES['csvfile']['tmp_name'];

$file = fopen($csvfile, "r"); //we now open the file
$filesize = filesize($csvfile); //get the filesize

$contents = fread($file, $filesize); //read contents of the file
fclose($file); //close file

$linecount = 0;
$linedata = array();

//you can modify "\n" if your csv file is ended differently
foreach(split("\n",$contents) as $line)
{
$line = trim($line," \t");
$line = str_replace("\r","",$line);
$line = str_replace("'","\'",$line);
$linedata = explode(",",$line);
$mysqlline = implode("','",$linedata);
$linecount++;

//insert the data into the database
//replace $yourtablename with your mysql table name
$sql = mysql_query("insert into '.$yourtablename.' values('$mysqlline')");
}

That's it. We have a simple php script that accepts a csv file and then reads the contents and save the data into your mysql database. Of course this still needs to be optimize. We need to check if the file input is really a csv file. Or is the file empty or too large? I will leave it up to you.

Oh, and be sure that you connect to mysql first. :)

Still raining very hard

This storm just won't stop! Good thing my internet connection is fine now. But I really need to go out to buy some food. I haven't eaten for 8 hours now.

In the meantime, please check my other blog if you're into DOTA (a custom game for warcraft 3). It's my in depth guides and strategies for DOTA.

I hope this rain storm stops soon. I can't work if I'm very hungry. I will post again soon when I've done the things I need to do today( that also means I've already eaten. hehe).

Wednesday, November 21, 2007

Another web programming day with phpGoogleStoreLocator Part 2

It's been a very slow day... at least for my programming. As for everything, it's been a very tough day. We've been hit by a big typhoon and it's been raining very for almost 2 days now. It even became a super typhoon on some parts of the country and lots of properties were destroyed already. Internet here also went down for about 12 hours. What a day!

Anyway, I just continued working on my current project which involves the phpGoogleStoreLocator script. What I did last time did great, according to my boss, but what is needed is to make the template look a lot better and add some functions on the admin area. Functions include having a control for the admin to add data for the store maps by uploading csv files or grabbing the data by downloading a csv file for the existing database. And also a few additional controls to further control the store locator script.

I'm also starting on another project about a fund raising website. The project looks good and sounds very interesting. The web site helps fund raisers reach their goals through sports online.

This is it for now. I will go through further details next time.

Tuesday, November 20, 2007

Another web programming day with phpGoogleStoreLocator

It's been a very tiring day for me. It's raining hard the whole day. Today, I continued with what I have been programming the past 2 days. I've been working on a store locator for a dietary supplement drink website. I've been using this very cool php script phpGoogleStoreLocator which you can download here.

phpGoogleStoreLocator is an application that uses the Google Maps API service which can serve as a store locator in your website. It is very easy to set up and these are all you need to get it running:

  • Google API Key (http://maps.google.com/apis/maps/)
  • Webserver with php 4.0+
  • MySQL 3.0+
Very good right? It is compatible with different browsers too. These are the browsers that are compatible with it right now:
  • Internet Explorer 5.5+
  • Mozilla/Firefox 1.0+
  • Safari 1.2+
  • Konqueror 3.0+
  • Galeon 1.2+
  • Epiphany 1.0+
  • Flock 1.0+
  • Opera 9.01
To install, just extract the files to a directory and run install.php. You will know what to do when you get there. Remember to delete your install.php file after installing.

Some of it's features are :
  • A Google Map
  • Customizable Map Icons
  • Balloon images for store locations
  • Stores are searchable by country, street address, city, state and zip code.
  • Support for address level geocoding for the US, UK, CA, AU, All of Europe, Taiwan, India, and New Zealand
  • City level geocoding for the entire planet
It also has an admin panel and a customizable layout which is very easy. You can see the full features here.

What I have been doing the past 2 days were modifying some parts of the script and also the template to suit the site owner's requirements. So far so good and it's working like the way he wanted it to be. I'm just waiting for some feedbacks after he finished testing the site. If there are any problems then I will be working on it again tomorrow. For now I'll be on stadnby on that part and I'm going to work on another project for another client. I'll talk about this one tomorrow.