Posts

Showing posts from August, 2011

Coldfusion - assign value of a database query to a variable using CFSET and CFQUERY

I know its rare that anyone uses ColdFusion nowadays, but today, I had to add in a little "feature" to an in-house web application in my company, which was developed using ColdFusion.  Looking at the timestamp of the files, the application was built way back in 2001. Woah, that's like 10 years ago! @.@ Whats worse is that, I have never used ColdFusion to develop full web applications before! And we all know how difficult it is to modify OTHER PEOPLE'S codes.  So I had to do a bit of guesswork and lots of Googling before figuring out how to do a VERY SIMPLE thing: how to assign the value of a database query to a variable. It was fun seeing the thing work though I must confess, I am still a fan of ASP.NET ;) <cfquery name="getcompanyinfo" datasource="mydatabasename" dbtype="ODBC" > select c.companyid, c.address, c.tel from companies c where c.comp_name like '%#companyname#%'</cfquery> <CFSET COMPANYID = getc

Move an object using jQuery animate() function

Today, I am going to share a simple code snippet to show you how you can move an object in a webpage using jQuery’s animate() function. You can click this link to see a demo of this example. To try out this example, you will need to prepare an image file, e.g. I use one called “picture.gif” in my example and type out the following skeleton code first. I will assume you are familiar with <div> tags and CSS, and how to set element properties such as absolute positioning and left / top position etc. <html> <head> <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script> <style> #canvas {background:white;width: 100%; height: 100%; } #picture {width:48;height:139;position:absolute; left:0;top:50;} </style> <title>Demo jQuery Move object</title> </head> <body> <div id="canvas"> <img id="picture" src="picture.gif" /&g

How to use JSON, jQuery and mySQL in PHP

Image
Today, I dabbled for the first time with PHP, JSON, jQuery and mySQL. I am writing this post for my own reference as well as hoping that it will be useful for others who are trying to do something similar as I was. If you are too lazy to try out the code yourself, you can access this page to see a demo of what this code does . The code snippets provided below will help you to accomplish these tasks: Fetch data from a mySQL database and convert it to JSON data (demo_mysqltojson.php) Invoke an AJAX call to the PHP script above upon a button click using jQuery that returns JSON data, read and convert the JSON data to array-like records that can be iterated and used. (demo_showjsondata.php) Create a JSON array and send that JSON array via an AJAX call to a PHP script (demo_jsontomysql.php) that will add it to a mySQL database demo_mysqltojson.php <? $con = mysql_connect("localhost","demouser","demopassword"); if (!$con) { die('Could not

mysql newbie problem: Error 1045 (28000)

Image
Tried to install mysql Community Edition on my PC just now and encountered the error message as shown in the screenshot below: Error 1045 (28000): Access denied for user 'root@'localhost' (using password: NO) Fortunately, the problem is very easy to solve and needs you to specify to the SQL command-line interpreter that you want to specify a different password to log into the root account.  You just need to type "mysql -u root -p" and press Enter. The command-line tool will prompt you for your root password and once you supply the matching password, you will see the log-in screen as below: