RedCoupe

MS SQL Server – get second from last record

by on May.18, 2011, under Web design / development

Using MS SQL Server, I’ve been trying to get the second from last record that had been created because I want to do some comparison code to display what has been changed.

Anyway just form future reference here’s the SQL I used:

SELECT TOP 1 *
FROM dbo.tbl_MailList_Items
WHERE item_id < (SELECT MAX(item_id) FROM dbo.tbl_MailList_Items)
ORDER BY item_id DESC

This works perfectly for my situation and doesnt rely on just subtracting 1 from the id column because my id column is not fully incremental due to records being deleted etc.

Leave a Comment more...

Killzone 3

by on Mar.15, 2011, under PS3

Well what can I say, I’m finding this game absolutely awesome. The graphics and sound are fantastic and both the single player campaign and online multiplayer are incredibly addictive.

When I first played this I thought the controls seemed a bit kind of ‘sloppy’ but having spent quite a few hours on it, I’ve got used to it with no problems.

Big thumbs up for me, love it!

Leave a Comment more...

Ubuntu subdomains on Apache2

by on Sep.21, 2010, under Web design / development

From a standard Apache2 install I created a folder in /var/www/ called ‘testsite’ (without the quotes).

Go to the following folder:

/etc/apache2/sites-available

…and create a file called something suitable, for this purposes of this blog post I’ll just call my file testsite, It’s contents should be:


DocumentRoot /var/www/testsite/
ServerName testsite.localhost
ServerAlias testsite.myubuntubox

Options Indexes FollowSymLinks MultiViews +Includes
AllowOverride None
Order allow,deny
allow from all

Then run the following command:

sudo a2ensite testsite

Edit your /etc/hosts file and add the following lines:

127.0.0.1 testsite.localhost
127.0.0.1 testsite.myubuntubox
192.168.0.6 testsite.myubuntubox

Obviously the ip address 192.168.0.6 may be different depending on your network setup.

Restart Apache:

sudo /etc/init.d/apache2 reload

I also had to edit my c:\windows\system32\drivers\etc\hosts file on my other PC to make sure that when I visit http://testsite.myubuntubox/ it resolves correctly, so I now have the following:

127.0.0.1 localhost
192.168.0.6 myubuntubox
192.168.0.6 testsite.myubuntubox

That’s it, all working, now I can develop multiple websites locally using subdomains. Personally I would rather do it this way than putting websites into folders, seems to work better with Dreamweaver.

Leave a Comment more...

Change date/time format from MySQL

by on Sep.17, 2010, under Web design / development

Format was: 2010-09-17 12:09:01

But wanted to display like: 17-09-2010 12:09:01

<?php echo date('d-m-Y H:m:s', strtotime($row_Recordset1['datetimeval'])); ?>

Related links:

Leave a Comment more...

PHP replace crlf in a textarea with br

by on Sep.09, 2010, under Web design / development

I had a textarea value which was obtained from a MySQL database and it contained many instances of crlf or \n. To display correctly on a web page I wanted to convert those to <br /> so I used the following code:

<?php echo nl2br($myrecorsetvalue); ?>

Obviously you would need to replace the $myrecorsetvalue with whatever recordset variable you are using.

Leave a Comment more...

Random rows in MySQL

by on Sep.08, 2010, under Web design / development

A competition has been running on a website and all the entries were stored in a MySQL table.

Had to get a random record to pick a winner once the closing date had passed.

Here’s the SQL I used:

SELECT *
FROM t_tablename
ORDER BY RAND()
LIMIT 1

If I had wanted to pick out 5 random winners, then change the LIMIT value to LIMIT 5.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!