tips posts

IE Can Only Handle 31 Stylesheets -- Thanks IE!

Yes, our old friend Internet Explorer is at it again to make our lives as web developers miserable.  Not many know this, but in IE, a single web page can only reference at most 31 <link>'d CSS stylesheets. For hand-coded pages, this probably isn't a problem.  But when you start using larger CMS systems and applications, like Drupal, you can very quickly run into the 31 stylesheet limit.  This happens in currently all versions of IE, including IE 8.

ie_sucks_sm-300x225.pngMost of the time this problem presents itself, the web developer believes he or she is going insane.  Your site looks beautiful in FireFox and Chrome, but in IE everything is off: some things are positioned weird, fonts are the wrong size, etc.  And IE doesn't warn you or let you know this is happening in any way, so you are left to go silently mad trying to figure out what the problem is.

There are a couple possible solutions:

  • Combine stylesheets into single, large files.  This may not always be practical or very organized, but hey, you've got to do what you've got to do.
  • Use @import instead of <link>
    • For example:
      <style>
      @import url('a.css');
      </style>
    • IE seems to be okay with this, and will allow more than 31.  However, @import isn't as great, performance-wise, as <link>.  Also, it may cause stylesheets to be loaded out of order, which can cause JavaScript problems.
  • If you are using Drupal, you can try the modules http://drupal.org/project/ie_css_optimizer or http://drupal.org/project/unlimited_css to get around the IE problem.

 Let's hope that the next version of IE lifts this bizzare restriction (but I'm not holding my breath).

Oracle_query() and Other Oracle Convenience Functions

Attached File(s): 

If you're used to using MySQL with PHP, you already know of the simple and easy to use mysql_query(), mysql_fetch_object(), mysql_affected_rows() and so forth functions.  Well, if you've ever dipped your toes into the tepid waters of Oracle, you know that it lacks the friendly PHP functions that MySQL has.  So, I created a set of convenience functions designed to mirror the MySQL ones.

Just download the attached file at the top, and use it like so:

<?php
  
  include_once("oracle_common_functions.php");

  oracle_connect($username, $pass, $host, "TEST");
  $res = oracle_query(" SELECT * FROM $table_name ") or echo(oracle_error());
  while ($cur = oracle_fetch_array($res)) {
    var_dump($cur);
  }  
  
  oracle_close();
  
?>

Just remember that to use any of this, you also need PHP to be compiled with the necessary oci libraries.

Complete list of functions in the file:

oracle_connect()
oracle_query()
oracle_fetch_array()
oracle_fetch_object()
oracle_affected_rows()
oracle_close()
oracle_error()
oracle_errno()
oracle_escape_string()

Enjoy!

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Meet My Friend, Mr. Curly Brace

The curly brace (also known as the curly bracket) is a fairly powerful tool in PHP.  In a nutshell, it lets you specify the name of a variable in a string.  Why is that so important?  Because what if you want to specify a member variable to an object in another variable?  Maybe an example would elucidate the problem...

Let's say you want to compare apples to oranges in a standard object...

$obj = new stdClass();
$obj->apples[] = "Granny";
$obj->apples[] = "Red";
$obj->apples[] = "Bad";

$obj->oranges[] = "Navel";
$obj->oranges[] = "Tangerine";

Now, let's say that you need to access either the apples array or the oranges array based on some other variable, $fruit

PHP Tip: Sorting Multidimensional Associative Arrays

We've all faced this problem before.  You have a multidimensional associative array, and you need to sort it by some element right in the middle.  Or even sort by several elements.  How do you do it?  Well, here's a quick tip that will keep you from having to program custom comparison routines to get usort() to work.

For example, let's say your array looks something like this:

// array structure:  $a[person name][age][pet name] = pet age

$a["mary"][35]["spot"] = 5;
$a["bob"][29]["nosy"] = 8;
$a["mary"][35]["fido"] = 12;
$a["bob"][29]["eve"] = 2;

Now let's say you want to know the order of pet names, sorted by owner's age, then pet age, then person name, then pet name.  If we go the traditional usort route, we would have to program several annoying and confusing comparison functions.  So, here's the trick:  flatten out the array!

 


Software License Fine Print

Creative Commons LicenseThis code is licensed as-is, with no warranty or guarantee, under a Creative Commons Attribution 3.0 Unported License.

You may use this code however you want, even in commercial products, but only if you include attribution to me, Richard Peacock, as the original author of this small portion of code, but not in a way that implies I endorse your project.

For example, on a Help/Credits screen:  Portions of this project were based on work freely obtained from these developers: Richard Peacock (http://richardpeacock.com), NAME HERE, etc.  These outside developers neither endorse nor support this software.

If you use this code, feel free to email me to let me know!  I'll include a link to your project here.

Syndicate content