Easy SQL Insert for Multiple Rows

Here’s a quick and easy way of inserting data.

INSERT INTO Beatles (FirstName, Surname)
SELECT ‘John’, ‘Lennon’
UNION ALL
SELECT ‘Paul’, ‘McCartney’
UNION ALL
SELECT ‘George’, ‘Harrison’
UNION ALL
SELECT ‘Ringo’, ‘Starr’
GO

We start with INSERT INTO and the name of your table followed by the names of the fields in order in brackets. Then, for each row you want to insert you simply put SELECT followed by the values. String values for a varchar field will need to be put in single quotes, integer or boolean values can be given without. Next, add a UNION ALL line between each SELECT line. Note, don’t put this before the first or after the last, only between. Finally, add a line with GO at the end. Bang! Data’s inserted.

Posted in INSERT, SELECT, SQL, UNION | Tagged , , , | Leave a comment

Nintendo Wii Menu Style Hover Buttons with jQuery and CSS3

I’ve tried to replicate the large menu buttons used on the Nintendo Wii Menu using CSS3 and jQuery for the animation.

Demo:

Option 1
Option 2
Option 3
Option 4
Option 5
Option 6
Option 7
Option 8
Option 9

To use it you need to have jQuery referenced in your page, for example:

<script type=”text/javascript” src=”jquery-1.5.min.js”></script>

You can optionally use cross browser CSS3 effects but this may slow things down or make text look distorted in some browsers.

Here’s the CSS:

#container
{
position:relative;
width:660px;
height:360px;
margin-left:auto;
margin-right:auto;
background-color:#eee;
}
.button
{
width:200px;
height:100px;
background-color:#ccc;
border:solid 1px #333;
text-align:center;
position:absolute;
font-size:2em;
line-height:3em; /* centers text vertically */
}

Here’s the jQuery code:

<script>
$(document).ready(function(){

$(“.button”).mouseover(function(){
$(this).animate({
width:’240′,
height:’140′,
top:’-=20′,
left:’-=20′,
fontSize:’2.8em’,
opacity:’1′
},200).css(“z-index”,”9″);
});

$(“.button”).mouseout(function(){
$(this).animate({
width:’200′,
height:’100′,
top:’+=20′,
left:’+=20′,
fontSize:’2em’,
opacity:’0.8′
},200).css(“z-index”,”0″);
});

});
</script>

The jQuery uses the mouseover and mouseout events. When the mouse hovers over a button the animate function increases the size of the button and simultaneously moves it upwards and left so that the growing appears to be equal in all directions rather than just down and to the right. The font size is also increased in proportion to the button dimensions and the opacity increased from 0.8 to 1.0 to give greater weighting to the hover button. Finally, the hover button is given a z-index higher than the non hover buttons so that it appears in front of them.

Finally, here’s the HTML:

<div id=”nintendo-container”>
<div class=”button border-radius20 opacity80″ style=”top:20px;left:20px”>Option 1</div>
<div class=”button border-radius20 opacity80″ style=”top:20px;left:230px”>Option 2</div>
<div class=”button border-radius20 opacity80″ style=”top:20px;left:440px”>Option 3</div>
<div class=”button border-radius20 opacity80″ style=”top:130px;left:20px”>Option 4</div>
<div class=”button border-radius20 opacity80″ style=”top:130px;left:230px”>Option 5</div>
<div class=”button border-radius20 opacity80″ style=”top:130px;left:440px”>Option 6</div>
<div class=”button border-radius20 opacity80″ style=”top:240px;left:20px”>Option 7</div>
<div class=”button border-radius20 opacity80″ style=”top:240px;left:230px”>Option 8</div>
<div class=”button border-radius20 opacity80″ style=”top:240px;left:440px”>Option 9</div>
</div>

The HTML uses the style attribute to position each button absolutely.

Posted in animate(), css, JavaScript, jQuery, opacity, Uncategorized | Tagged , , , , , , , , , , , | Leave a comment

Animated Scrolling Page Background Effect

Influenced by video game menu design, I was curious to see if I could make a tiled background image scroll on a web page. After a lot of hunting I found this neat bit of JavaScript and jQuery.

To use it you need to have jQuery referenced in your page, for example:

<script type=”text/javascript” src=”jquery-1.5.min.js”></script> 

Then, simply put this in your page head:

<script type=”text/javascript”>
        // scroll background image vertically
        var scrollSpeed = 30;
        var step = 1;
        var current = 0;
        var imageHeight = 100;
        var headerHeight = 600;
        var restartPosition = -(imageHeight);
        function scrollBg(){
            current += step;
            if (current == restartPosition){
                current = 0;
            }
        $(‘body’).css(“background-position”,”0 “+current+”px”);
        }
        var init = setInterval(“scrollBg()”, scrollSpeed);
</script> 
Posted in JavaScript, jQuery | Tagged , , , , , , , , , | Leave a comment

CSS3 – Creating a Quick Effects Stylesheet

I’ve found myself using the same few CSS3 effects time and time again. Rather than recode these effects into every project I’ve created a quick effects stylesheet, a mini library, of the effects I use most often.

The CSS3 effects used here are all cross browser compatible, using standard CSS3, vendor prefixes and a combination of Microsoft filters and HTC behaviors to handle effects not supported by IE browsers.

The effects I’ve used are:

  • Border-radius (rounded corners)
  • Box-shadow (drop shadow effect)
  • Opacity (varying the transparency)
  • Rotate
  • Text-shadow
  • Gradient (backgrounds that fade from one colour to another)

Download the zipped folder, stylesheet and behavior files

Posted in border-radius, box-shadow, css, opacity, text-shadow, transform | Tagged , , , , , , , , , | Leave a comment

Events Not Firing in ASP.NET

There can be all sorts of reasons why events aren’t firing in a Web Form but here are a couple of things I’ve found usually cause the problems:

1. Other forms

If you have a page which includes another set of <form> tags, either nested within your main form or outside in your template, this can cause problems. It’s ok to have more than one form on a page but make sure they’re separate, that each starts and ends before the next, rather than having any overlap or nesting. Forms within forms are bad news.

2. JavaScript

Events which are activated on the client side can often be interrupted by other conflicting JavaScript events. Try commenting out script blocks or references to them and see if this allows your events to fire.

Posted in ASP.NET | Tagged , , , | Leave a comment