Import CSV Files into a MySQL Database

Web Developer have to face a large amount of obstacles in their every day tasks in order to complete them. There are some thing that are easier to complete than other but a little bit of help can make a big difference when it comes down to finishing on time. Importing a CSV file into a MySQL database is often needed when creating projects for new clients. This is because they will use a variety of desktop software and they will probably tell you, “Here you go” when it comes to geting the data. To your advantage most of this applications have some way of exporting their data into Comma Separated Value files or CSV. Basically it’s a file that has a layout similar to a spreadsheet but instead of boxes for columns you have a coma separating the fields. In the same way in lieu of rows you will have a new line in the document.

The first step is to get that file from the customer or from it’s source and upload it into your server. After this you will need to access your server’s command line via an application like Putty and start your MySQL server.

$ mysql -h localhost -u root -ppassword

You will need to create your database with the fields that you will be needing. once your database has been set up you can import the data from your CSV file into your MySQL database. Here is the command that you will require in order to import the information into your database table.

load data local infile 'myphpdeveloper.com/httpdocs/_assets/cities.csv'
into table phpdev.gc_cities
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(zipCode, city, state, county, areaCode);

In the first line of the command is where the location to your Comma Separated Values or CSV file is located at. The second line is the table that you want the information to go into. The third line is telling your MySQL server that the values are separated by comas. In the same way the fourth line is describing how the values are enclosed by single quotes. The fifth line is telling your server that your row ends when the line end. Finally the sixth lane is the fields in your database table. They need to be aligned with the order of your file for example if your files is ID, Price, Description then your locations will be (id, price, description) and so on.

Often there are times that the above command will not work. This is due to the fact that this option is considered to be a big security risk. Some hosting companies like Media Temple are disabling this by default so you will need to make a couple of small changes in order for it to work.

You will have to locate your MySQL configuration file which is usually located at ‘etc/my.cnf’ and comment out the line that prevents the import. You will have to do this while being a root user in your server, if not it will only allow you to read the file but not to reconfigure it. The line that you are looking for is:

local-infile=0

You will have to comment it by adding a “#’ sign at the beginning of the line like:

#local-infile=0

You can learn more about this on the MySQL Documents. After you have completed the change you will need to restart the MySQL server and then do the process once more. The command to restart the server is:

service mysql restart

Hope that this helps any web developers out there. Please feel free to leave any comments, questions or suggestions down below and we will be happy to assist you.

Google +1 Button is Going International

The biggest search engine in the market Google has announced that they will be launching the +1 Button internationally. The Google +1 button is the company attempt to gain ground on Facebook Like button. However, because of the Google brand behind social meter it can assist brands to generate more trust in their sites when they have many +1’s. Until now this has been showed only on English results but it has now been released to sites across the world wide web. This is great news for Hispanic and international brands that are running an online marketing campaign.

Here are some of the countries where the +1 button is firstly going to be rolled out at:

  • Google.Co.Uk
  • Google.De
  • Google.Jp
  • Google.Fr

Quickly after this initial expansion has been completed they will start to expand further into all other Google search result portals. Webmasters can now go into Google Webmasters Central and use the +1 button tool to generate code snippets to +1 buttons which is available in 44 different languages. The Official Announcement was made today on Google’s Webmaster Central Blog.

A Successful Inbound Marketing Campaign

Many people now a days are starting to talk more and more about inbound marketing when it comes to creating a business advertising campaign. Inbound Marketing methods are ways in which the clients come to you instead of you reaching out to them. This is very important in this times because people know that by going to the internet they can get what they want in a more accurate way and without having to look at complicated ads or thing that they just dont want to see. A great example of this is how 90% of purchases are researched online before the actual purchase is made. Imagine if people go online to research what product to buy and you keep coming up in their searches they are more apt to select you versus any other competitor.

A great way to do inbound marketing is through search engine optimization for organic or non-paid search results. By doing this people use to trust your brand more than if they reach you by a paid advertisement method like it is on the case of a Pay Per Click Campaign. This however is not something that you will be able to succeed in just a few months; it will take a lot of time and dedication in order to see the full results of a successful inbound marketing campaign. There are more methods however that will assist you in having a successful and trusting inbound marketing campaign.

A very important factor that is growing exponentially is Social Media. It can be Twitter, Facebook, LinkedIn or any other channel but the fact is that people are spending more and more time in this channels and the conversations are going on with or without you. Twitter for example is a great way to let your customers know of what you do, how you do it, how your business interacts and so on. By this I’m not saying to just send advertisements out there but interact in conversation. Help people who need is looking for some answers, little tings will take you a long way in making friendships. This friendships will talks about how great you are to their friends and that will bring you more trusted business.

Even tough in order to run a successful inbound marketing campaign you will need more brains than money, in the long run it will make you more money while keeping your cost lower. Don’t be afraid of having to look for new friends, be afraid of you loosing them as that will be the first step for failure. Inbound Marketing is not the future of advertisement but the present, what are you doing about it?

 

Google Analytics eCommerce Tracking

Here is the script that needs to be added to the receipt or confirmation page, after the user has completed the sale. You will just need to add php inside of the script so that the content can be created dynamically per customer. One tip is to use a PHP loop. Here is the code:

<script type="text/javascript">



ξ var _gaq = _gaq || [];

ξ _gaq.push(['_setAccount', 'UA-XXXXX-X']);

ξ _gaq.push(['_trackPageview']);

ξ _gaq.push(['_addTrans',

ξ ξ '1234', ξ ξ ξ ξ ξ // order ID - required

ξ ξ 'Acme Clothing', ξ// affiliation or store name

ξ ξ '11.99', ξ ξ ξ ξ ξ// total - required

ξ ξ '1.29', ξ ξ ξ ξ ξ // tax

ξ ξ '5', ξ ξ ξ ξ ξ ξ ξ// shipping

ξ ξ 'San Jose', ξ ξ ξ // city

ξ ξ 'California', ξ ξ // state or province

ξ ξ 'USA' ξ ξ ξ ξ ξ ξ // country

ξ ]);



ξ ξ// add item might be called for every item in the shopping cart

ξ ξ// where your ecommerce engine loops through each item in the cart and

ξ ξ// prints out _addItem for each

ξ _gaq.push(['_addItem',

ξ ξ '1234', ξ ξ ξ ξ ξ // order ID - required

ξ ξ 'DD44', ξ ξ ξ ξ ξ // SKU/code - required

ξ ξ 'T-Shirt', ξ ξ ξ ξ// product name

ξ ξ 'Green Medium', ξ // category or variation

ξ ξ '11.99', ξ ξ ξ ξ ξ// unit price - required

ξ ξ '1' ξ ξ ξ ξ ξ ξ ξ // quantity - required

ξ ]);

ξ _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers



ξ (function() {

ξ ξ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ξ ξ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

ξ ξ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

ξ })();



</script>

Creating custom 404 page

Everyone at some point has been browsing trough google or their favorite search engine and clicked on a link just to go into a white page with the words ???404 Error??? up on top. After this the only thing you have is to hit the ???Back??? button on your browser. As a user, this means that you go backand try another link. As a developer do, it means that you lost a potential clients, and that you have a glitch in ξyour application that you are not aware of.

You can set upt a custom 404 page using your apache .htaccess file. Here is how to do this:

  1. Access your server via FTP
  2. Make sure that you can see hidden files
  3. Locate for .htaccess
  4. If .htaccess does not exist go ahead and create it
  5. Open the file
  6. Type: ErrorDocument 404 /404.php
  7. Save the file
  8. Now you can go and edit this file so that you can have a custom error page.

That is all that you have to do in order to set up your server to have a custom 404 page. Use your imagination on this one, for examle you can have a search function or related pages to what the user was looking for. You can also have this page email you so that you become aware of the situation.

Hope this helps, any questions or concerns can be submitted below.

Basic AJAX connection using the POST method to retrieve content

Hello guys,

I have been working on a project for school which used AJAX and I just wanted you guys to have this code for reference. This code basically makes a call to a PHP script which gets Zip Code information (city and state) and then adds them into your web page. I used a span tag with id of ???zipinfo??? to act as a holder for the content that was going to be retrieved. Hopefully this helps some of you in your projects.

//Get Zip Code Information

function zipInfo(zipcode) {

fieldValue = ???connection=zipInfo&zip=???+zipcode;

var url=???includes/management.php???;

httpRequest(???POST???, url, true, fieldValue, function(result){

document.getElementById(???zipInfo???).innerHTML = result;

});

}

//AJAX Request

function httpRequest(reqType, url, asynch, fieldValue, callback) {

request = new XMLHttpRequest();

request.open(reqType,url,asynch);

request.setRequestHeader(???Content-type???, ???application/x-www-form-urlencoded???);

request.setRequestHeader(???Content-length???, fieldValue.length);

request.setRequestHeader(???Connection???, ???close???);

request.send(fieldValue);

request.onreadystatechange = function() {//Call a function when the state changes.

if(request.readyState == 4 && request.status == 200) {

callback(request.responseText);

}

}

}

Creating a Sample HTML5 Structure

 

TML5 is the thing that developers are starting to take a look more and more. More and more browsers are getting compatible with it and with the iPhone choosing this as it???s main multimedia language I have no doubt that this will be demanded in great quantities. In this post I will explain how to create a sample HTML5 structure for your web site.

<!DOCTYPE HTML>

<html lang="en">

<head>

<meta charset=utf-8>

<title>Sample HTML5 Structure</title>

<style>

header, nav, article, footer, address, section {

ξdisplay: block;

}

#container {

ξwidth:900px;

ξmargin:auto;

ξbackground-color:white;

}

header {

ξbackground-color:#666;

}

nav li {

ξdisplay:inline;

ξpadding-right:1em;

}

nav a {

ξcolor:white;

ξtext-decoration:none;ξ

}

nav a:hover {

ξtext-decoration:overline;ξ

}

h1, h2 {

ξmargin:0px;

ξfont-size:1.5em;

}

h2 {

ξfont-size:1em;

}

footer {

ξbackground-color:#999;

ξtext-align:center;

}

</style>

<script>

document.createElement("article");ξ

document.createElement("footer");ξ

document.createElement("header");ξ

document.createElement("hgroup");ξ

document.createElement("nav");ξ

</script>

</head>

<body>

<div id="container">

ξξξ <header>

ξξξ ξ<h1>Sample HTML5 Structure</h1>

ξξξξξξξ <nav>

ξξξξξξξξξξξ <ul>

ξξξξξξξξξξξξξξξ <li><a href="#">Home</a></li>

ξξξξξξξξξξξξξξξ <li><a href="#">About</a></li>

ξξξξξξξξξξξ </ul>

ξξξξξξξ </nav>

ξξξ </header>

ξξξ <section>

ξξξ ξ<hgroup>

ξξξξξξξ ξ<h1>Main Section</h1>

ξξξξξξξξξξξ <h2>This is a sample HTML5 Page</h2>

ξξξξξξξ </hgroup>

ξξξ ξ<article>

ξξξξξξξ ξ<p>This is the content for the first article</p>

ξξξξξξξ </article>

ξξξξξξξ <article>

ξξξξξξξ ξ<p>This is the content for the second article</p>

ξξξξξξξ </article>

ξξξ </section>

ξξξ <footer>

ξξξ ξ<p>This is the Footer</p>

ξξξ </footer>

</div>

</body>

</html>

As you can see the syntax is very similar, the start tags changed somewhat, but it makes it more convinient for the coder. Alsoas you can see now instead of making separate divs to stylize the header and footer, now HTML5 gives you a specified tag for each of them. The <nav> tag is the where your main site navigation will be at. You can also see the <section> tag, this will define the differents parts of your page, for example articles, blogroll, etc.ξ The <hgroup> tag is used to group various content heading, for example when you have an Article title and a Subtitle.

The JavaScript part of the code will create the tags so that older browsers and IE will accept them. This step is very important, if you do go ahead and skip it then older browsers will have trouble understanding your ode and the results will vary a lot.

Please leave any comments and/or suggestions below,

Gilberto Cortez

Image Resizing with PHP

Hello guys,

Today I will post a image resizing script, this will assist you in all of your sites specially ecommerce ones in which you need to display your products with different sizes. The script is self explanatory, but please send me a message or a comment if you need further assistance with it.

//Image Target

$pic = ???images/???.$_GET[‘pic’];

//Set Max Sizes

$max_height = 48;

$max_width = 48;

//Get Image Size

$size= getimagesize($pic);

//Set Ratios

$width_ratioξ = ($size[0] / $max_width);

$height_ratio = ($size[1] / $max_height);

if($width_ratio >=$height_ratio)

{

$ratio = $width_ratio;

}

else

{

$ratio = $height_ratio;

}

//Set new size

$new_widthξξξ = ($size[0] / $ratio);

$new_heightξξ = ($size[1] / $ratio);

//Set header

header(???Content-Type: image/jpeg???);

//Create Image

$src_img = imagecreatefromjpeg($pic);

$thumb = imagecreatetruecolor($new_width,$new_height);

imagecopyresampled($thumb, $src_img, 0,0,0,0,$new_width,$new_height,$size[0],$size[1]);

imagejpeg($thumb);

imagedestroy($src_img);

imagedestroy($thumb);

All you need to do now is to point the src element of your image tag to this script, and set the file you desire using the get method. Ex: img.php?pic=image.jpg

Please contact me with any doubts,

GilbertoξCortez

Interactive Web Development for ???The Cloud???

Lesson 2: Pre-Production Process and Market and Keyword Analysis

This is the second part of a series of search engine optimization lessons. On this lesson I will start to explain you what I call the “Pre-Production” process of your campaign. At the start of each campaign one must do a market and keyword analysis research. Market Research is when one researches and evaluates the current online competition for that specific client. By doing this you will be finding out who your actual competition is and what they are doing to stay on top of things. You can find your competition by using different methods, one of them is by doing a search on the keywords that you think your client will rank for, and you will notice that some websites will start to looking familiar after a while. Write them down in a document.

Once you complete your list, go back and start analyzing each of this websites. I usually note the 10 most relevant competitors that I will be going against to in the Search Engine Results Page or commonly known as the SERP. Take a close look at these sites as these competitors are doing something right because they are currently ranking for what you want. The most important things to look at are what they are using in their Meta Tags, most importantly the content of the Title Tag and the Keyword Meta Tag. Start writing in a document a list of all of the keywords that you think is important; they will help you when you start doing your own keyword research. Each client will be a different type of business so try to learn as much as you can about the business when you are doing this. It will help you throughout the project and when conversing with the client as you will be more knowledgeable. You can also find out how hard or easy it will be for you to rank for the specified keyword. If your competitors all have page rank of 6 and 7 then it will be a pretty though road to beat, nothing is impossible tough.Once you complete a full evaluation of competitors, you will continue into starting your keyword analysis. A keyword analysis needs to be done in order to find a list of appropriate target keywords. By appropriate I mean keywords that you will be able to effectively rank for and bring traffic to their web site and increase their ROI (Return on Investment). There are many tools out there that can help you do this, there is one that I have found the most useful. The Google Ad Words Keyword Tool, which is free of cost to use. In order to take advantage of all of the features that this tool can offer you should create a Google account and log in each time before you use the keyword tool. This tool will provide you with all the relevant information for your project. On the top box you will input ideas of keyword that you have might thought that you wanted to rank for. The keyword tool will return you with up to 800 related keywords, find the ones that you think are the most important to your site and store them in an Excel spreadsheet, save the keyword and the traffic – for this I use Global Monthly Searches. Make sure that you do not repeat them, and start sorting them out by similarity. Once you think you had enough go back and try organizing them once more. At the end sort each of the categories by traffic. This will now be the keyword which you will base your campaign on.Click Here to Download my Sample Spreadsheet to save the information you have found on your research.While doing your keyword researches you should know this. Don???t try to rank for a keyword that you are never going to get. Example: Don???t go and try to rank for Music Videos when trying to rank an upcoming artist debut video, try ranking for something more relevant like ???Upcoming Pop Artist {Artist Name} Music Video??? which will bring you better result. But also don???t go and only try to rank for keywords that does not have any traffic to it as it will not bring you a lot of traffic. Also, try using a thesaurus or a dictionary to find others way that people could write your term as. This might bring you additional traffic that not a lot of people are going after but that a lot of people might be searching for.

In my next lesson I will teach you how to take these keywords and start using them to optimize your web pages. Hope that you liked this lesson and please if you did share it below via Twitter or Facebook. And once again if you have any questions or comments please write them on the form below.

 

Lesson 4: Internal and External Linking

This is the fourth part of a series of [kastooltip msg=”search engine optimization” tooltip=”The process of improving the visibility of a website or a web page in search engines via the natural search results”] lessons. On this lesson I will be explaining you the methods to do internal and external link campaigns. Linking is probably the most important factor at this time on ranking for a specified term. There is internal linking which refers to the linking within your domain. There is external linking which refers to links that are pointed into your site from external domains. During this lesson I will be referring to anchor text constantly, by this I refer to the text that is within your anchor link html tags.

 

Example: (Anchor Text is Highlighted)

<a href=”linking-example.php” title=”Linking Examples”>View Linking Examples</a>

As you can see there are two more factors to this anchor tag that are in it. The href is the URL where you are pointing the link to. This URL needs to contain a keyword that you are trying to go for. If your links are going to be directed to a dynamic script where you will have multiple variables in them, try using URL Rewrites to make SEO friendly URL???s. The title is basically the title of your link, again try to use a keyword in here when writing these tags.

Internal linking is taken into consideration by Google in different ways. First it will take the keywords that are used throughout to link your site together. Some example of this links include your main navigation, footer navigation, call to actions, etc.

Example:

To link to an online marketing company about page, the tag will look something like:

<a href=”about-online-marketing-company.php” title=”About Online Marketing Company Interactive Utopia”>About Online Marketing Company Interactive Utopia</a>

As you can see we use our keywords to create our anchor tags for our site. Try to avoid using images or JavaScript for your navigation as this is not read by spiders. The best method to create your site navigation is UL lists and CSS to make it look good. Also if it???s an important page, remember to link it from a main navigation and don’t have it hidden. I will go a little bit further on this subject on another lesson.

External linking is probably the most important ranking factor at the moment. This is because the search engines believe that basically the more people link to you the better your content is suppose to be as it satisfies all of this different people. The first thing to remember is to try to get all the links to your site to have keywords that you want to rank for in the anchor text. There are different methods that you can use to generate external links to your site.

A good way to do this is to write and distribute press releases. You can create these ones for different events that you will be sponsoring, or for products that you will be launching, etc. On this press releases include your keyword rich links and use a press release distributor to publish your release. If your release is relevant to the public it will be caught up by different news sites, and when they publish them some of them will include your links on them.

Another good method is to have a blog in your site and continuously write on it. This will create more content on your site for users to read and if they like it they will share it with their friends, or on their web sites. Try to have a way to share your content easily. If you are using a CMS like WordPress, Drupal, or Joomla! They all have a plug in that can do this for you.

You can also have a link exchange. This is when you know the owner of another site and he agrees to link to your site if you link to his. This will help you but the algorithm gives less authority to these types of links. The one with the most are the one-way links or links that link to you but you do not link back to them. There are a lot of different creative ways

My next lesson will be about setting up analytics and goals on your site to track your progress. This is very important as you need to keep track if your theories are working. If you see that traffic is going up or down. Or if you see traffic but no conversions. This is all problems that you will only be able to resolve trough looking at your site analytics. Hope that you enjoyed this lesson, please if you did share it below via Twitter or Facebook. If you have any questions or comments please write them on the form below.

 

error

Enjoy this blog? Please spread the word :)