by Brad on September 12, 2011

Sometimes it’s just impossible to create a functional website without needing to store arrays into a database. Traditionally, the implode() and explode() php methods can work wonders. What about inserting a multidimensional array into a MySQL database using php though? I could’ve gone without doing it, but in trying to be as efficient with queries as possible I found the need to do it for this project.

My form code looked like the following (my backend php stripped out):

<p><label><input name="checkbox[10]" value="15" type="checkbox">Gas Fireplace</label></p>
<p><label><input name="checkbox[15]" value="10" type="checkbox">Wood Fireplace</label></p>

This would output an array like this:

[10]=>15
[15]=>10

If you were to simply insert the array as follows, you’d only get the word Array in there:

<? mysql_query("INSERT INTO database (key) VALUES ('".$_POST["checkbox"]."')"); ?>

However, by serializing the data first. You get something much more complex:

<? mysql_query("INSERT INTO database (key) VALUES ('".serialize($_POST["checkbox"])."')"); ?>

Instead of getting the word Array, you’ll get something more like this:

a:56:{i:9;s:8:"cable tv";i:47;s:0:"";i:10;s:0:"";i:15;s:0:"";i:27;s:0:"";i:37;s:0:"";i:36;s:0:"";i:3;s:0:"";i:32;s:0:"";i:6;s:12:"only outside";i:35;s:0:"";i:26;s:0:"";i:34;s:0:"";i:16;s:0:"";i:8;s:0:"";i:48;s:0:"";i:24;s:0:"";i:11;s:0:"";i:25;s:0:"";i:22;s:0:"";i:17;s:0:"";i:50;s:0:"";i:4;s:0:"";i:18;s:0:"";i:49;s:0:"";i:13;s:0:"";i:20;s:0:"";i:12;s:0:"";i:14;s:0:"";i:21;s:0:"";i:19;s:0:"";i:23;s:0:"";i:7;s:0:"";i:46;s:0:"";i:40;s:0:"";i:42;s:0:"";i:38;s:0:"";i:45;s:0:"";i:44;s:0:"";i:43;s:0:"";i:41;s:0:"";i:39;s:0:"";i:1;s:0:"";i:2;s:15:"only small dogs";i:51;s:0:"";i:52;s:0:"";i:53;s:0:"";i:54;s:0:"";i:58;s:0:"";i:57;s:0:"";i:55;s:0:"";i:56;s:0:"";i:28;s:0:"";i:30;s:0:"";i:29;s:0:"";i:31;s:0:"";}

All you have to do now is simply unserialize the database results and poof, you just put your multidimensional array into your MySQL table using PHP

<? $result=mysql_query("SELECT key FROM database LIMIT 1");
$row=mysql_fetch_row($result);
print_r(unserialize($row[0])); ?>

Good luck and happy coding :)

Tags: , , , , , , , ,

by Brad on September 7, 2011

We decided to add a member button that users could put on their website to symbolize their partnership with us referrals. In order to make the image look good, we had to use both truetype fonts and center the text. Unfortunately the gd library only allows xy coordinates, which means an additional function to determine where the text needs to go in order to center it.

The following php function will return the xy coordinates you need to center your truetype text in an image using the gd library:

function CenterImgText($image, $text, $font, $size) {
 $xi = ImageSX($image); $yi = ImageSY($image);
 $box = ImageTTFBBox($size, $angle, $font, $text);
 $xr = abs(max($box[2], $box[4])); $yr = abs(max($box[5], $box[7]));
 $x = intval(($xi - $xr) / 2); $y = intval(($yi + $yr) / 2);
 return array($x, $y);
}

Here is an example of the function in use, $image being the variable for the image you have created in gd:

$font_size=10;
$font="tahomabd.ttf";
$text="Your Text Here";
$color=imagecolorallocate($image,255,255,255);
list($x, $y) = CenterImgText($image,$text,$font,$font_size);
ImageTTFText($image,$font_size,0,$x,$y,$color,$font,$text);

Hope this helps someone else :)

Tags: , , , , , , ,

by Brad on August 31, 2011

In order to make the hosting over here a bit more efficient, I had to merge a couple older less powerful cpanel servers into a new server. Luckily, they’ve added some great features for migrating accounts in the whm panel. Using the built in functions cpanel has to offer, I was able to move well over 400 cpanel accounts to the new server. In total it took about 6 hours to synchronize all the settings and accounts but a majority of the process was automated.

  1. Login to the whm panel of the server you are moving the cpanel account(s) to
  2. If you are moving a single account, select “Copy an account from another server with account password.” If you are moving a reseller or multiple accounts, as I was, select “Copy multiple accounts/packages from another server.”
  3. For the remote server address, put in the IP address or hostname of the server you are pulling the cpanel accounts from.
  4. For authentication, you can select root if you have root access or simply use the username/password of the reseller account if you do not have root access. If you are logging in as a reseller, choose sudo as the root escalation method. You can ignore all the other options and click “copy account” or “fetch account list.” I had some trouble fetching one of the servers account lists but it was due to it being an outdated version of cpanel. Despite the security, I disabled SSL to fix the problem.
  5. Just watch cpanel do the rest and ensure there are no errors. Depending on the number of accounts and comined size of all the files, this process can take several hours.

If you have an existing hosting account and are looking for a more reliable service or are just starting out, the company I work for offers some very affordable shared priced hosting packages via uPilot.com. If you mention this blog post, I’ll make sure you get a free month just for signing up.

Tags: , , , , , , ,

by Brad on August 11, 2011

In the process of setting up a couple wordpress powered websites, I had the need to create a two tiered drop down navigation menu. You can call the navigation menu in your theme’s file by using:

<? wp_nav_menu(array( 'menu_id'=>'navigation' )); ?>

Simply paste the following javascript code between your header tags, and include the jquery library:

 <script language='javascript'>$(document).ready(function(){
$("#navigation li").hover(function(){
$("ul", this).slideDown("fast");
},function() {
$("ul", this).slideUp("fast");
});
});</script>

Here’s some example css for a menu I created recently:

#navigation navigation { float: left; text-align: left; width: 836px; height: 39px; padding-top: 7px; }
#navigation li { float: left; list-style: none; padding-right: 15px; margin-right: 5px; background-image: url('../img/nav-spacer.png'); background-position: right 0px; background-repeat: no-repeat; }
#navigation li a { font: 13px tahoma; font-weight: bold; color: #fff; text-transform: capitalize; letter-spacing: 1px; text-decoration: none; }
#navigation li a:hover { color: #b8ebff; }
#navigation li ul { display: none; list-style: none; width: 180px; padding: 25px 10px 10px 10px; margin-top: -2px; background: url('../img/childbg.png') repeat-y; position: absolute; }
#navigation li ul li { width: 190px; padding: 0px; margin: 0px; float: left; background: none; border: 0px; }

It only takes a few more lines of code to make it three tiered navigation menu for wordpress. Here’s a screenshot of what the final version looked like for me:

Our company designs custom themes, menus, plugins, and more! Don’t give yourself a headache trying to figure it out unless you want to. Contact us today to find out more about how we can help you develop your website using wordpress as a content management system.

by Brad on August 6, 2011

I’m not the only person who hates the oversized and outdated PDF format… I conducted a poll on another website of mine to get an idea of how popular the format really is. The blog had no specific target audience: the results spanned people of all generations and areas of the US. Although I didn’t receive thousands upon thousands of votes, 91% of the hundred~ people who did vote agreed that PDF files are a bad idea.

A couple months ago my roommate and I decided to place an order at Pizza Shuttle in Milwaukee. I had been used to a very ugly but extremely functional website which they had been using for years. Although the website was extremely disappointing to the eye years ago, the entire restaurant menu was built into the website itself. It was easy to read, easy to navigate, and we ordered food from them at least twice a month using the website as our menu. Nevertheless, the new website required me to download a PDF file of the restaurant’s menu. Disgusted that their new web design company would allow this to happen, I downloaded it anyway… I’m running a quad core processor with 4gb of ram on my laptop, and this PDF file was so obnoxiously built that every time I scrolled down half an inch on the menu the entire page would turn white and have to rerender itself. It took minutes of time just to browse through the appetizers list. My roommate told me to give up on Pizza Shuttle, and suggested we order from Toppers instead. Although I believe Pizza Shuttle’s food tasted much much better, we were forced to order from their competition’s website as the Pizza Shuttle menu was simply impossible.

I decided to view Pizza Shuttle’s website again today before writing this article. It appears they were able to realize how bad of an idea the PDF menu was. They replaced it with a freeware flash-based document viewer which is more functional than a PDF but still looks extremely tacky, is still a horrible idea when it comes to search content/seo/etc, and could still be improved upon greatly. The viewer is written in flash, which means non-Android smartphones will be unable to view it. Not only that, a customized  CSS/HTML/jQuery based viewer would’ve taken less than an hour to create and would not be littered with advertisements and documents from other companies. The new viewer fixes the PDF problem, but makes Pizza Shuttle look like they don’t care about their internet presence. Also, anyone typing in “pizza and fried chicken” or “bbq chicken pizza milwaukee” should be directed to Pizza Shuttle. Because they have chosen both PDF and Flash formats recently, they’ve essentially killed any ability to pull traffic for anything except someone searching for “Pizza Shuttle” itself. Flash kills the search engine possibilities here. A quick google search for “Buffalo Chicken Pizza Milwaukee” returns NYPD pizza which is located on North Ave, Domino’s Pizza, Ian’s Pizza, La Piazza Pizza, Pizzeria Scotty on Oklahoma Ave, and a few others. In typing “Milwaukee pizza and fried chicken” I receive results for Zayna’s Pizza, Andrea’s Pizza, Shakey’s Pizza and Buffet, Bacci Pizza, and more. Pizza Shuttle is #8 for the keyword, and it’s by a complete fluke…

These aren’t the only two item specific food searches that Pizza Shuttle is missing out on. Potentially hundreds of customers a month who might have stumbled upon their site for a specific food are going to be calling companies like NYPD pizza instead. The new Pizza Shuttle design is a large improvement in appearance but a few steps backward when it comes to their rankings, marketing, and search presence.

Don’t make the same mistake Pizza Shuttle and hundreds of other restaurants have made in developing their online presence… Please contact us to find out how we can boost your search engine rankings and overall search engine presence.

Tags: , , , , , , , ,