• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

Coding

VARCHAR vs TEXT Performance

May 21, 2011 by Webhead

Ever wonder if VARCHAR(255) or TEXT is a better data type?  This thread suggests VARCHAR(255) is better because it is allowed to use MEMORY (or RAM).  The TEXT data type is not allowed in there.

http://forums.mysql.com/read.php?24,105964,105964#msg-105964

 

Although it was also found that a larger VARCHAR like VARCHAR(3000) has worse performance than TEXT (in MyISAM).

http://nicj.net/2011/01/20/mysql-text-vs-varchar-performance

 

The general rule appears to be to use VARCHAR if it is less than 255 characters and to use TEXT if it’s 255 or more.

Filed Under: Coding Tagged With: mysql, optimize

Optimize MySQL using EXPLAIN

May 20, 2011 by Webhead

If you need to optimize or find out how a MySQL query is doing, type in “EXPLAIN” before the query and you’ll get a table that shows a bunch of statistics.  I’m not going to try to explain them all.  It can be found on the MySQL docs site:

http://dev.mysql.com/doc/refman/5.0/en/explain-output.html

Filed Under: Coding Tagged With: mysql

Favicon

May 17, 2011 by Webhead

Problem

When the simplest things don’t work it can drive you nuts.  I had a task to add a favicon to a website so that it shows in the browser.  To do this all I thought I had to do was get the PNG, convert it to a .ICO file on one of the many online converters and place it in the home directory of the website.  What do you do when the image shows at http://mydomain.com/favicon.ico but doesn’t show as the browser’s page icon?

Solution

  • Clear the browser cache
  • Make sure you have the link tag in the <head> part
    <link REL="SHORTCUT ICON" HREF="/favicon.ico">
  • Go here and make sure your icon is up to the standards

When I looked at Firebug I saw that there was a tag <link rel=”icon” href=”” type=”image/x-icon” >.  I thought it was a little strange, but I also thought Firebug was just interpreting the icon location since it wasn’t in the source code I was looking at.  (Firebug shows the real-time values of elements instead of the actual code.  ie. if you use javascript to move an element, it will show the new coordinates instead of the original ones).

After a while, I found the website that validates favicons.  Once I saw that extra “image/x-icon” again, I looked through my PHP code and saw that it was including that, which is why I didn’t see it in the main html code.

Filed Under: Coding Tagged With: html

Creating an Instance of a PHP Class

May 15, 2011 by Webhead

Problem:

This works in PHP 5.3+:

$CLASS_NAME = 'TheName';

$class_instance = new $CLASS_NAME;

This doesn’t

define('CLASS_NAME', 'TheName');

$class_instance = new CLASS_NAME;

 

Workaround:

Use the way that works.  There are other limitations with using a variable to create a class.  Another way to create a class from a variable is by using:

$test = call_user_func(array($className, 'getInstance'));

 

Filed Under: Coding Tagged With: php

No table-cell or table-row in IE CSS

May 13, 2011 by Webhead

Internet Explorer, How do I loathe thee?
Let me count the ways.

As stated on the w3schools website,

[quote]The values “inline-table”, “run-in”, “table”, “table-caption”, “table-cell”, “table-column”, “table-column-group”, “table-row”, “table-row-group”, and “inherit” is not supported in IE7 and earlier. IE8 requires a !DOCTYPE. IE9 supports the values.[/quote]

I had a project where I needed to create a photo gallery.  The goal was to get the gallery to look like iStockPhoto with the images all bottom-aligned, evenly spaced, etc, etc.  Well in creating the gallery I had a hard time aligning the photos on the bottom, so I took a look at how istock did it.  They use “table-cell” display option and vertically align the image to the bottom.  So I tried it, but soon found that Internet Explorer does not support that option.  And then I found that istock was no exception.

iStock with Chrome

 

iStock with IE

 

Solution:

I did not personally do this solution as this was not too important.  However someone on Stack Overflow seems to have solved it with jQuery:

$(document).ready(function(){
  if ($.browser.msie && $.browser.version == 7)
  {
    $(".tablecell").wrap("<td />");
    $(".tablerow").wrap("<tr />");
    $(".table").wrapInner("<table />");
  }
});

the above script assumes you have divs using style such as:

<style>
.table     { display: table; }
.tablerow  { display: table-row; }
.tablecell { display: table-cell; }
</style>

 

Filed Under: Coding Tagged With: css, IE crap

Get All rows into One String

May 13, 2011 by Webhead

This is an easy way to get all rows from a SQL table into a string:

select stuff((
                  select ', ' + a_column
                      from [name_of_table]
                      order by table_id
                      for xml path('')
                  ), 1, 1, '')

Filed Under: Coding Tagged With: ms sql

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 27
  • Go to page 28
  • Go to page 29
  • Go to page 30
  • Go to Next Page »

Primary Sidebar

Topics

apache apple bootstrap buddypress chrome cloudways cms css debug drupal eCommerce firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery kinsta linux localization mac os x ms sql mysql open source optimize php php 7.2 svg tinymce woocommerce wordpress wpengine xss yii youtube

Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools
  • Uncategorized