mysql table column named ‘default’ not working!

April 19th, 2009

I was having a hard time figuring out what the problem with my mysql query was, and so this might help someone.I had a column named in my table called ‘default’ which was just a tinyint (or boolean) 1 or 0 so that I could indicate if the row was meant to be the default row for a page. However my query that said:

“select * from table where default=1″   

Wasn’t working at all.It was giving me the same unhelpful error “you have an error in your SQL syntax. Check the manual blablabla”.Then I rememberd that the word “default” in mysql syntax is used to specify what you want the default value to be for a column when you are setting up a new one.

So if you use it as a column name it wont work and will go mental.I then changed it to be “isdefault” and it worked fine.It soon came to my attention that it’s a really dumb idea to label your column names anything that might conflict with some mysql query code.

In the same way it wouldn’t make sense to name a column “where” or “select” or “update” or any other mysql syntaxy word.But you probably aren’t idiots and already know this…. 

Round your values in PHP using Math Functions (using number_format)

April 19th, 2009

To round any number or integer values in PHP it’s simple.number_format is useful function that you can use. It takes 2 values: the $NumberYouWantToFormat and then the number of decimal places you want it to be formatted to. 

$total = 34.128252 echo number_format($total, 2)

This will produce:

34.13 

It’s a simple thing, but really useful.