Saturday, January 5, 2008 at 3:22 AM
Over on TalkPHP, there is a wee contest running with the essential idea being to swap around the values belonging to two variables in 8 lines or less. There are very simple, very obvious ways of doing this which you would normally use (I don’t think I’ve ever actually had to swap the values of two variables in real coding!) but for fun, the entire point of the contest is to be creative with the solutions.
We are presented with
and quite simply, the aim is to end up with $a having a value of 2 and $b having a value of 1. Easy!
Read More »
Sunday, December 9, 2007 at 1:53 AM
Using SimpleXML to acquire the conversion rates, and storing it in JSON format to be used in the conversion itself. This article introduces some rather impressive functionality to further your PHP skills.
read more | digg story
Wednesday, September 19, 2007 at 9:33 PM
Introduction
In this article, I’ll be talking about a useful new feature introduced in PHP5 as part of the OOP improvements over PHP4. This feature is called Method Chaining and enables us to do pretty cool things like:
$object->method_a()->method_b()->method_c();
Read More »
Monday, September 17, 2007 at 3:02 PM
Hi folks,
We all use printf (or sprintf) to help ourselves when mingling together output strings with our variables, right? This is a tip that I use often, but I continually see people writing code where this technique would be useful but isn’t used. What _am_ I on about? Read More »
Thursday, March 15, 2007 at 4:13 PM
I’ve been working with Stored Procedures a lot recently, even though the whole idea was new to be before starting this job. Today I was trying to select the first n rows from a table, but wanted to be able to change n via a parameter in the procedure call. I thought something like the following would work, but it throws an error when trying to use the variable for the TOP clause.
CREATE PROCEDURE dbo.sp_TestGetAll
@LIMIT int
AS
SELECT TOP @LIMIT
id, col1, col2, col3
FROM TestTable
After a brief Google search there were a few methods presented including such nasties as manually writing out a SQL string within the procedure and executing that instead! Also, it was suggested to change the ROWCOUNT variable before and after issuing the select. Sheesh, that’s messy.
Well anyway, the solution which works for me and is much easier is simply to wrap the variable in parenthesis and magic… it works.
CREATE PROCEDURE dbo.sp_TestGetAll
@LIMIT int
AS
-- Notice the parentheses around @Limit - that is the only change!
SELECT TOP (@LIMIT)
id, col1, col2, col3
FROM TestTable
I’m just really noting this down so that I don’t forget, do another Google search and then resort to those other ugly ways of doing this simple task.