notbanksy's blog

Web Design, Linux and other nonsense

Hide javascript from evil IE6

After much frustration at the hands of joomla, and general bloated software realated apathy, the latest episode of Notbanksy’s blog brings you a complete idiot’s guide to javascript.

If like me, you’re a complete idiot when it comes to javascript, then this post is for you, my friend. While away endless hours marvelling at this little script I put together all by myself.

Actually, I copied and pasted bits and bobs from other scripts I found on the net till i found a combination that worked. Still, I’m glowing with self esteem now, so it’s time to share!
Read the rest of this entry »

Filed under: ie6, javascript

Mootools 1.2 and MenuMatic in Joomla 1.5

So, you’re using Joomla and you want to include a decent, accessible vertical flyout menu such as MenuMatic (which is fantastic by the way)? If that describes you, then I have 2 pieces of advice for you:

  • Stop using Joomla – it’s horrible.
  • Read this article, it will tell you how to do it.

The main obstacle to using MenuMatic in Joomla is that it doesn’t work! The reason for this is because Joomla includes Mootools version 1.1 and MenuMatic requires Moo version 1.2. You’ve probably guessed that they’re not compatible.

Now what really irritates me, is the fact that Joomla only makes use of mootools in the administrative area, yet the developers have seen fit include the mootools library in the front end also…. So the task at hand is to keep Mootools version 1.1 for the back end (trust me, it’s totally unusable without it), but switching to Mootools version 1.2 for the front end.

Read the rest of this entry »

Filed under: joomla, php

Swine Flu: Anti Swine Ware

You may have all noticed that the aporkalypse is upon us, thus I have taken it upon myself to save you all from the new terror.
Copy this file into a text editor, save it as antiviral.php, and then add  <?php require(‘antiviral.php); ?> to index.php of your personal site.

You may have all noticed that the aporkalypse is upon us, thus I have taken it upon myself to save you all from the new terror.

Copy this file into a text editor, save it as antiviral.php, and then add  <?php require(‘antiviral.php); ?> to index.php of your personal site.

Let me know if you spot any bugs ;p

<?php

if (!$_POST['life']) {
$funeral=TRUE;

break;
}
if (!$sneezing && !$coughing && !$fever) {
Read the rest of this entry »

Filed under: swine flu ,

Essential linux commands for web developers

This list is by no means exhaustive, but it should cover most eventualities for developers using linux. If you haven’t yet tried developing a website on a linux machine, then do so immediately! Thank you.

Some of the commands included here also appear in a previous post of mine – Top Linux Terminal Tips, so apologies to those obsessive followers (you know who you are!) for this small amount of repetition.  I should also credit ErisDS for prompting this artice – pop over to her fantastic musings of ErisDS blog; there’s some great stuff there. And apologies to Eris for not covering all her suggested topics… Way too much for one post, but watch this space!

Read the rest of this entry »

Filed under: bash, linux

Php MySQL Random Quotes

Here’s a quick tutorial for implementing a random quote on your site using php/ mysql.  It’s not the most imaginitive script ever, but it’s a sound bit of learning for php noobs, and does have practical applications. It can be used for testimonials, or anything at all (ok, that’s a bit of an excessive claim, but it’s a bit useful). The techniques covered will definitely come in useful at some point in your programming career.
It may seem counter intuitive to use a database to randomise a few quotations, but I’m going to assume scalability is the issue at hand here, and that you’re going to end up with hundreds of quotes. Whatever justifies it will do! Besides, I’ll show you a quick php only script at the end for those who think a database is too much trouble.
First we’ll need a database called quote. Then you will need to set it up to take the entries like this:
<?php
//connect to mysql
mysql_connect(“localhost”,”yourusername”,”yourpassword”)or die(mysql_error());
//connect to database
mysql_select_db(“quote”)or die(mysql_error());
mysql_query(“CREATE TABLE quotes(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
quotation TEXT,
author VARCHAR(165))”)
or die(mysql_error());
echo”table created!”;
?>
Easy!  Feel free to mess with the paramaters there – some of you may not want to allow for massive quotations, so you may decide to use VARCHAR for quotation too. All depends on the verbosity of your sources!
So your database is set up, and your positively bursting with literary intent? Grand!  Next part is to create a form to input the quotations, here it is, and it’s (almost) good old HTML :) We’ll call it add_quote.php
<form action=”<?php echo $_SERVER['PHP_SELF']; ?>” method=”post”>
Quote<input type=”text” name=”quote”>
Author<input type=”text” name=”author”>
<input type=”submit” value=”add new quote”>
</form>
You’ve probably seen <?php echo $_SERVER['PHP_SELF']; ?> before? If not, it is just a way of telling the form that it should be processed by the document it lives in – by it’s SELF in other words. Ok, so we have a field to input the quote, and author – now we need to capture the data and squirt it into the database. Don’t forget to connect again, too:
//connect to mysql
mysql_connect(“localhost”,”yourusername”,”yourpassword”)or die(mysql_error());
//connect to database
mysql_select_db(“quote”)or die(mysql_error());
if ($_POST) {
$quote=$_POST['quote'];
$author=$_POST['author'];
//create new db entry
mysql_query(“INSERT INTO quotes(quotation,author) VALUES(‘$quote’,'$author’)”)or die(mysql_error());
}
Notice the if statement there? It prevents the form from capturing any data unless anything has been POSTed using the submit button. Next we assign the data to variables imaginitively called $quote and $author.  The next bit I hope is self explanatory.
Finally on this page, we should show which quotes we have added already – so that we don’t accidentally duplicate any.
//get quotes from database
$query=”SELECT * FROM quotes”;
$result=mysql_query($query)or die(mysql_error());
//list quotes
while($row=mysql_fetch_array($result))
{
echo”<div><p>”.$row['quotation'].” ~ “.$row['author'].”</p></div>”;
}
Again, self explanatory stuff so simple even an army of monkeys could reproduce it!  We SELECT everything (* means everything in SQL) FROM our table (quotes) and assign the output to a variable: $result. Then for each row ($row) in the results (mysql_fetch_array($result)) we output the quote and author ($row['quotation'] & $row['author']) and some appropriate HTML.
Job done mate – and for convenience I would put a link to your random quote page under your form to check it works:
<a href=”random_quote.php”>See a random quote!</a>
You’re nearly done – the next page random_quote.php uses some code we’ve already written but with important differences, so I’ll hold your hand till we reach the other side. Step one connect to the database:
<?php
//connect to mysql
mysql_connect(“localhost”,”yourusername”,”yourpassword”)or die(mysql_error());
//connect to database
mysql_select_db(“quote”)or die(mysql_error());
You’ll be a dab hand at connecting to mysql by now! The next part of the process is to choose a random quote, but in order to do so, we need to know how many quotes are avaiable. Here’s how we count them:
//count number of quotes in database
$num_quotes=”SELECT COUNT(*) FROM quotes”;
$count=mysql_query($num_quotes)or die(mysql_error());
This should be pretty simple to understand – the query asks simply to COUNT every enrty FROM the table quotes, then assign the result to $count. The weird this is, that $count doesn’t come back as a number on its own – if you were to echo it now, you’d get something like resource id=3. Weird, huh? So this next bit of code strips away the unnecessary and just leaves the number of quotes on its own.
//format the count
$count = floatval($count);
Now we have the actual number of quotes assigned to our var, we can choose one at random – a number between 1 and the total number of quotes.
//choose a random quote
$num = Rand (1,$count);
Now pull that quote out of the database on its own. Each time a quote is added, it is given an id number which mysql automatically assigns (check back to AUTO_INCREMENT when we created the table). So by finding the id field with the corresponding random number we have located our random quote!
//get chosen quote from database
$query=”SELECT * FROM quotes WHERE id=$num”;
$result=mysql_query($query)or die(mysql_error());
Now, print it on the screen already!
//display quote
while($row=mysql_fetch_array($result))
{
echo”<div><p>”.$row['quotation'].” ~ “.$row['author'].”</p></div>”;
}
?>
And you’re done! Easy, wasn’t it?  Here’s the two files in full for all you copy and pasters out there.
add_quote.php
<form action=”<?php echo $_SERVER['PHP_SELF']; ?>” method=”post”>
Quote<input type=”text” name=”quote”>
Author<input type=”text” name=”author”>
<input type=”submit” value=”add new quote”>
</form>
<a href=”random_quote.php”>See a random quote!</a>
<?php
//connect to mysql
mysql_connect(“localhost”,”root”,”harlequin”)or die(mysql_error());
//connect to database
mysql_select_db(“quote”)or die(mysql_error());
if ($_POST) {
$quote=$_POST['quote'];
$author=$_POST['author'];
//create new db entry
mysql_query(“INSERT INTO quotes(quotation,author) VALUES(‘$quote’,'$author’)”)or die(mysql_error());
}
//get quotes from database
$query=”SELECT * FROM quotes”;
$result=mysql_query($query)or die(mysql_error());
//list quotes
while($row=mysql_fetch_array($result))
{
echo”<div><p>”.$row['quotation'].” ~ “.$row['author'].”</p></div>”;
}
?>
random_quote.php
<?php
//connect to mysql
mysql_connect(“localhost”,”root”,”harlequin”)or die(mysql_error());
//connect to database
mysql_select_db(“quote”)or die(mysql_error());
//count number of quotes in database
$num_quotes=”SELECT COUNT(*) FROM quotes”;
$count=mysql_query($num_quotes)or die(mysql_error());
//choose a random quote
$count = floatval($count);
$num = Rand (1,$count);
//get chosen quote from database
$query=”SELECT * FROM quotes WHERE id=$num”;
$result=mysql_query($query)or die(mysql_error());
//display quote
while($row=mysql_fetch_array($result))
{
echo”<div><p>”.$row['quotation'].” ~ “.$row['author'].”</p></div>”;
}
?>Here’s a quick tutorial for implementing a random quote on your site using php/ mysql.  It’s not the most imaginitive script ever, but it’s a sound bit of learning for php noobs, and does have practical applications. It can be used for testimonials, or anything at all (ok, that’s a bit of an excessive claim, but it’s a bit useful). The techniques covered will definitely come in useful at some point in your programming career.

It may seem counter intuitive to use a database to randomise a few quotations, but I’m going to assume scalability is the issue at hand here, and that you’re going to end up with hundreds of quotes. Whatever justifies it will do! You can see this script in action here.

First we’ll need a database called quote. Then you will need to set it up to take the entries like this:

<?php

//connect to mysql
mysql_connect(“localhost”,”yourusername”,”yourpassword”)or die(mysql_error());

//connect to database
mysql_select_db(“quote”)or die(mysql_error());

Read the rest of this entry »

Filed under: php

Php MySQL gig listing script tutorial part 2

Welcome to part 2. This part is a lot lighter than part 1; I’m sure you’ll fly through it. Basically we’re going to walk through the administrative functions of editing, cancelling and deleting gig listings. At the end I’ll list all the files needed to make the admin area actually work, such as login, logout etc. No explanation of these other files will be given as I explained in part 1. A thorough look at them can be seen in my guestbook tutorial.

If you glance back at the end of part one, I left you with the buttons to edit, delete and cancel gigs. The first function we’re going to look at is editing. Here’s the file, it’s called edit_gig.php. All the while, you’ll notice that these administrative functions always start with a check to see if the user is logged in: Read the rest of this entry »

Filed under: linux , , ,

Php MySQL gig listing script tutorial part 1

After much fannying around and general breaking of things, I finally have produced a fully operational gig listing script for which I offer this humble tutorial. Hope you like it.

You may want to glance over the guestbook tutorial as much of the code for the secure login is reused for this script. I’m going to list the code again at the end of this tutorial, but if you want an explanation of how it works, you should head over to the guestbook tutorial.

First off a couple of things must be considered. This is not an all bells and whistles script. For example, this script will not detect if you enter a gig listing which is in the past, it anticipates a modicum of common sense – a feature all too lacking in modern web programming in my opinion! Also, it presupposes that you will not be booking gigs any longer in advance than max 2 years, min 1 year. If you’ve ever worked as a musician, you’ll realise that this is more than adequete. And for all those seasoned musos turned web programmers out there, yes there is a gig cancellation feature!
Read the rest of this entry »

Filed under: php , , ,

Linux Terminal: Simple Bash HTML Gallery generator

This is where being a linux user gives you a huge advantage over those Microsoft nambies!  Ever cursed those long hours spent writing out a massive HTML document after your client has given you 125 images for a new gallery page on their site?  I know I have, and I’ve got the square eyes and caffeine addiction to prove it.  What if linux could see those images, make a note of their names, and generate the bulk of that HTML for you?  Wouldn’t that be a relief?  Not to mention a massive saving of time and money too.  Well, it can!

This idea is so simple, and so easy to execute that it’s a wonder anyone anywhere is making web pages on a windows machine!  Feel free to laugh at anyone you know who is currently doing so.

Read the rest of this entry »

Filed under: bash, linux

Top Linux Terminal Tips

What’s the best thing about linux? For me, it’s the terminal, and I think it’s a real shame how so many people shy away from linux because they’re intimidated by the terminal, or command line interface (CLI). It’s such a waste, but I also understand, because it made me nervous too in the beginning. But once you get going, it’s actually much more fun than just pointing and clicking, and of course, you are giving yourself a ‘heducation’ at the same time, innit?

So here’s a few pointers to make your GUI-free experience beautiful!

//Time’s Arrow

How many of you have read Martin Amis’s ‘Time’s Arrow’? Well, it bears no relevance to this part of my post, other than to provide a catchy title, but if you must know, it’s about a German Holocaust doctor who experiences time in reverse. Read the rest of this entry »

Filed under: linux , ,

Php & MySQL Guestbook tutorial – Part 2

Welcome to part 2 of the guestbook tutorial. So, in part one, you learned how to add messages to the guestbook, and how to display them on the web page. Good stuff. In this part you’re going to learn how to create a password protected login area to delete those nasty spam attacks and perform other censorship!

Remember in part one we created a table in your database to hold the username and password of the administrator? Well, first things first that wants populating. For the sake of simplicity I’m only going to show you how to add a single username/ password, but you can have as many as you want!

Ok, so my example username will be TonyBlair and the password will be LiedToMe, as these are not only memorable examples, but also true. Here’s how we’re going to get this information into the database:

Read the rest of this entry »

Filed under: php , , ,

What’s notmrsbanksy up to?

Oh man! She's gone and set herself up as a dog rescue! Mostly saving pound dogs (UK) from being put down. Once Loved Dog Rescue.


She also lists UK pound dogs on her site Pound dog rescue link.


Boson has a new home!

Boson has a new home

WOOF!