Course Assignments

My Almost Completed Second WordPress Theme

I have been making this second Worldpress theme for the final project in my CMS class. Compare to the first theme I made, it has more customized features such as custom background and custom navigation menu, the design of the theme is more complex, and the theme layout becomes more standard. Here is an overview of its features copied from this page:

  • Custom background
  • Custom menu (only allow one level of drop-down menu)
  • Three widget areas
    • Left widget area – default widget is categories if no widget is set
    • Right widget area – default is the search form
    • Bottom widget area – default is tag cloud
  • Show category and tag list at the end of each post, display a message  if there is no category / tag assigned
  • Custom 404 page
  • Display 10 recent posts under each post

For more information on each of the above features, and to see the code snippets for them, read the original post.

This theme is still incomplete because I need to add the comments area on the post page, as well as some design changes. The deadline for this final project is next Thursday, July 22. I still have some time to finish up.

I will post the final progress of the theme and its source code when it’s completed.

Calculate the degrees from the given Data to draw PHP Graph

During the final exam for my PHP class today, I encountered a math problem that I learned long time ago. The problem is to draw a chart based on the data from the database in order to show the ratio between men and women on a pie chart. The number of men represented as blue and red represent as women. I thought that it was as simple as draw two arcs using imagefilledarc function. However, when I noticed that the data needs to be in degrees in order to use this function. I totally forget how to convert a number to a degree since I haven’t been practice math for two years. Thanks to Google, I learned how to do the conversion on Yahoo Answers. The formula that I came up with is the degree of each men and women equals the number of men or women divide by total number of men and women multiply by 360. Therefore I wrote the following code:

The f and m variables are URL variables, which means I can pass the number of males and females inside the normal img tag:

You can download the source code here to experiment with it. There is a MySQL database file inside the downloaded archive, which it contains the needed MEMBERS table for this script.

Path Navigation using PHP and ColdFusion

This morning I wrote a script for both PHP and ColdFusion that dynamically generate a navigation bar like the one in the Nautilus GNOME File Browser:

It uses URL values to generate content for the navigation bar. Basically, it convents the URL string to an array based on the “/” or “&,=” pattern. It then forms navigation bar like style by using converted array inside a loop. This technique is actually inspired by the professor in my PHP class. I came up with this idea when she talks about how to use one PHP page to translate to several languages based on the URL. The following code is based on this URL style:

Here is ColdFusion code:


<!—- Change it to CGI.SCRIPT_NAME for use with URL path —>
<cfset variables.urlQuery=CGI.QUERY_STRING>

<!— Use listToArray() to convert CGI variable to an array
Change & to / for use with URL path —>
<cfset variables.arrayQuery=listToArray(“#variables.urlQuery#”,’&’)>

<!— Use arraylen() to determine the size of the array —>
<cfif arraylen(variables.arrayQuery) NEQ 0>

<!— &gt; is the greater than symbol —>
<a href=”/Students/Students/0111″ title=”Home”>Home</a> &gt;

<cfloop from=”1″ to=”#arraylen(variables.arrayQuery)#” index=”i”>

<!— Doesn’t need this statement if used with URL path —>
<cfset variables.splitQuery=listtoArray(“#variables.arrayQuery[i]#”,”=”)>

<!— Doesn’t need this loop if used with URL path —>
<cfloop from=”2″ to=”#arraylen(variables.splitQuery)#” index=”o”>

<cfif variables.arrayQuery[i] CONTAINS “projectid”>
Projects &gt;
<a href=”?projectid=#variables.splitQuery[o]#”>Project #variables.splitQuery[o]#</a>

The following is PHP code. The URL path method mentioned in the above code also works in the code below:

if (!empty($query)) {
$query = $_SERVER[‘QUERY_STRING’];
$queryArray = explode(“&”,$query);$_SERVER[‘QUERY_STRING’] ?>
<a href=”
<?php if ($_SERVER[‘SERVER_NAME’]==’localhost’) { ?>
<?php } else { ?>
<?php } ?>
“>Home</a> &gt;

for ($i=0;$i<sizeof($queryArray);$i++) {
$splitArray = explode(“=”,$queryArray[$i]);
for ($o=0;$o<sizeof($splitArray);$o++) {
$firstLevel = $splitArray[$o];
$secondLevel = $splitArray[++$o];
switch ($firstLevel) {
case ‘project’: echo “<a href=”?page=projects”>Projects</a>”;
case ‘page’:    echo ”;
if ($firstLevel == ‘project’) {
echo ‘ &gt; <a href=”?project=’. $secondLevel . ‘”>Project ‘. $secondLevel . ‘</a>’;
if ($firstLevel == ‘page’) {
switch ($secondLevel) {
case ‘about’: echo ‘<a href=”?page=about”>About Me</a>’;
case ‘projects’: echo ‘<a href=”?page=projects”>Projects</a>’;

Google Maps API and ColdFusion

While I was experimenting with Google API for my CA 288 ColdFusion class final project, I discovered that the ColdFusion variables can be used within the script tag. So I tried it out. I put the cfoutput tag outside the script tag in order to use the ColdFusion variables inside the script tag. And then I added cfif statement inside script tag to set the default latitude and longitude values to New York if there is no URL variables. Here is the cfelse part of the code:

I also used ColdFusion variables to convert them into the JavaScript variables as you can see on the first two lines of code. I also added a marker to the map to show the accurate location for the data provided. This is best used for creating maps from a list of places. For usage example, go to To download the source code, visit

PHP Form Validation Tip


While doing the assignment for my CA 282 ( PHP class today, I came up with a trick to minimize the amount of code that I need to write for the validation rule of each form element. This trick especially best used for validating forms with lots of form fields. The following is the PHP code:

As you can see from the code above, I use split function to convert the combined form field names and the actual name for each form field to arrays. I then used a for loop to loop between form fields to validate the form. This is a simple form. It only checks all the form fields that left blank. You can use continue command inside the for loop for certain form fields that don’t need to be validated. You can also use email validation and password=password_confirm validation inside the for loop. Also note that the noVal id at the end of above code is just used to display the error massages to red color and bold.

The ColdFusion website is now fully data-driven

I learned a way to write code for the menus by using database instead of using cfswich. Now the course website is completely database-driven. I used the CMS approach to redesign the links in each menu. Here is the entire code for the content page that corresponce to the menu items:

<cfquery name=”qGetURL” datasource=”DSN0111″>
FROM tblMenu
<cfif isDefined(“URL.projectid”)>
menuID = #URL.projectid#;
<cfelseif isDefined(“URL.pageid”)>
menuID = #URL.pageid#;
menuID = 18;

<cfset filePath = ExpandPath(“#qGetURL.linkLoc#”)>
<cfif fileExists(filePath)>
<cfinclude template=”../#qGetURL.linkLoc#”>
<div id=”noVal”>Not Found</div>
<cfinclude template=”index.cfm”>

As you can see from the above code, the file location and the file names are stored in the database instead of the page content. This way, I can create web pages inside site directories and then include it to the website through database without change the above code.

I also plan to create a ColdFusion web application that can directly update the database without launch MS Access. Right now I’m using CFEclipse to write the ColdFusion code on my Fedora system and virtualized Windows XP through VirtualBox to modify and viewing the database. My goal for this web application is to allow me to modify or view the database with less or no MS Access usage.

For those who don’t know, my ColdFusion course is Microsoft Access based, not MySQL based. I successfully installed ColdFusion 9 on my Fedora system, but I failed to install MS Access driver onto the system. That’s why I plan to create this application in the next few weeks.

Learning PHP Object Oriented Programming

Today I have learned about using Object Oriented Programming (or OOP) in PHP. It is very easy once you understand the structure of the OOP and have lots of practice on this technique. I learned this while I was looking over my Google Reader before my PHP class. I’m taking beginning PHP course this semester. This means that the OOP topic is not included in this course. You need to know basic PHP structures like functions and loops in order to understand OOP. Fortunately, I already self-learned PHP language during the end of year in 2009 through Lynda,com. So I tried to use OOP in the PHP script. At first. I think that I will practice more of this technique because this is new to me. I followed the simple tutorial on this website. After finishing the tutorial, I went to attend the PHP class. To me surprise, it had a test today. I happened to need more practice over the OOP. I took the second part of the test which was the hands-on test entirely using OOP. Here ( is the Object-oriented based test page. The following is one of the classes I created:

I just learned the basics of Object Oriented Programming so I can only write these basic classes. As I learn more about OOP, I will improve my code for better readability and performance.

For more information and to learn more about Object Oriented Programming in PHP, visit this article on

Successfully using ColdFusion array for the First Time Without Knowing Anything

I just improved my ColdFusion class website ( I used more fileExists functions to automate the detection of the project files in the URL variables. Now I don’t have to worry about adding the projects to the cfswitch statement anymore. Here is the code snippet for one of my cfcase statements:

<cfcase value=”4″>
<cfif fileExists(filePath[4])>
<cfinclude template=”../projects/project4.cfm” />
<div id=”noVal”>This project is not available yet!</div>
<cfinclude template=”index.cfm” />

Noted that I used an array in the fileExists function. Here is the cfloop statement for the filePath array:

<cfloop from=”1″ to=”10″ index=”i”>
<cfset filePath[#i#] = ExpandPath(“projects/project#i#.cfm”)>

As you can see, I used an array inside cfset statement to store 10 ExpandPath functions. This is my first time to use the array in a ColdFusion variable. In fact, I didn’t know anything about how to use ColdFusion array. I just applied the array based on the other programming languages that I have already known. According to course syllabus, we should learn ColdFusion array at later chapter.

At first, I used filePath#i# inside the loop to declare a regular ColdFusion variable. ColdFusion outputted an error stated that “ColdFusion was looking at the following text: #” . Then I tried the traditional method of adding an array by surrounding the loop variable with a pair of brackets. I was very surprised that it actually worked.

I applied the same technique to the title of each webpage so that I no longer forget about adding project title to the title.cfm when completed a project. Here is the code snippet for one of the cfcase statements:

<cfcase value=”7″><cfif fileExists(filePath[7])>#titleName[7]#<cfelse>#defaultTitle#</cfif></cfcase>

The defaultTitle variable is the default title on the site homepage.

The following are the additional updates for the site:

  • Projects are now re-organized
  • Project 1 has become homepage
  • Project 2 has changed to project 1
  • New project 2, Advanced SQL, was completed and added to the homepage

Computer Concepts Assignment Aid Web App released

Comparison between original and digitized version

Note:  This is an old post. It may contain links that no longer exists.

I finally completed the project and will be released under CS 110 homepage over soon. The following are some features of the web application (NOTE: This application is primarily made to help me to finish the assignments easier. However, anyone can use it if it helps to make life easier. This web app doesn’t contain any database-related function nor server/client log script, so you can safe to use it):

  • Each text field is auto expandable thanks to the autoResize ( jQuery plug-in.

Each text field will automatically expand once text in the text field reached the bottom of the text field.

  • The ability to add more rows using PHP.

The default number of rows is 20. Once you reached the last row at the bottom of the page, the Add a New Row button will appear. NOTE: this button will disappear if I don’t enter anything to any three of the text fields, it assumes that I had completed entering the data. After clicking the button, the page will refresh and it will scroll to the bottom of the page to letting me to enter data in the new row. I use the scrollTo jQuery plug-in to achieve this effect.

  • The option to print out the completed sheet after clicking the Submit button.

Once I clicked the Submit button, two buttons will appear on both top and bottom of the page, print button and edit button. It allows me to print out the completed sheet in order to hand in to the professor. The buttons on the page will not print out with the assignment sheet. I specified the print style sheet to hide the buttons while printing.

  • The option to edit the fields after it was submitted by clicking the Edit button.

The Edit button is simply using history.back() Javascript function to go back one page. I have not think of a way to achieve this without using database or session variables yet since my goal is to not leave any trace of the application on the computer and on the server.

Here is the side-to-side comparison between the original (non-digitized) version of the assignment sheet and digitized one:

Comparison between original and digitized versionComparison between original and digitized version. Click the image to enlarge

The following is the URL for this web app if you want to go to it directly: