Saturday, February 14, 2009

Weekly Source Code: Create A Table With Hyperlinks In PHP

A friend is busy with a website and asked me how to create a table with hyperlinks using PHP/mySQL so in this Weekly Source Code edition I will explain just how.

First you need to connect to the database, for this you use the mysql_connect method, then you run your select SQL query and ouput the result in HTML.

See the sample code.

If you wish to open the result in a popup window then call a Javascript function from the anchor tag's onclick event, in the Javascript function you can open a window with

Please Note:

- I pass the record id to the updateuser.php page, this is so that the page know which user I wish to update.

- I refer to the record in the row via its field name, you can also refer via its record position in the result for example: $row[1] refer to "Firstname" field.

- This will display all the records in the table, you can add some paging to the table to only display like 10 records at a time.

- For basic PHP you output HTML this way where your PHP and HTML code get mixed, its generally a good idea to use a template framework like Smarty where application code is seperated from the presentation.


PHP mySQL Functions
PHP Manual

Friday, February 13, 2009

Altair 8080 - Bill Gate's Altair BASIC

The Altair was the first computer released to the public in January 1975 (check here for history) by MITS, it was a very ugly machine that could only be coded in machine/assembly language by flipping switches. Basically saying: "Real Programmer's Don't Need Keyboards!"

Bill Gates & Paul Allen wrote Altair BASIC which was Microsoft's first product.

I downloaded the Altair emulator and stuggled to get it working but after awhile I finally got it working coding my first "Hello World!" in Altair BASIC!! This is so good to use the first computer and popular programming language.

How to use:
  • Run the Altair emulator.
  • Load the disk with the Altair BASIC image.
  • Toggle (that is on e.g. binary 1) all keys from A15 - A8, A7 to A0 must be down.
  • Toggle EXAMINE
  • Toggle down A15 - A8
  • Toggle RUN
  • A console window will open with the Altair BASIC running.

Wednesday, February 11, 2009

Lucky Man: Weekly Cake

I'm a very lucky man! My wife is on a cake course so each week she must bake a cake.... so I'm lucky since it mean I'm going to get cake on a weekly basis :-)

Life is good to me!

See photo of the cake she came home with last night. Yummy!!

Tuesday, February 10, 2009

Weekly Source Code: Create A GUID In .Net

A GUID is a unique identifier that you can use as a reference since its always unique.

If you need a GUID without writting any code, then visit which will generate a GUID for you everytime you refresh the webpage.

The code below create a GUID in C# and then display it to the console window:

class Program
static void Main(string[] args)
System.Guid id = System.Guid.NewGuid();

You can also store a GUID to a database, more about that in a future post :-)

PS: Been hectic at work, will write more later.

Friday, February 6, 2009

Using God's Name

Something that has been making me really angry lately, so I just want to make an efford and talk about it.

Lately I've been hearing on the TV, in the IT world (as a programmer I'm part of the IT world) etc that people use God's name in swearing etc.

For example:

- When something good / bad happens then: "Oh My God!!" rather than just "Oh Shit!!!" or "Oh Fuck!!" I would rather use "Oh Shit!!" or "Oh Fuck!!" or some other swear word if you really want to use a swear word.

- Bill Gates (or some other rich IT guy) have "more money than God!!". Well God don't need money since everything He say happens. We need money... it anyway make us corrupt etc (what is currently happening in the economy is a good example of that)

- "A visit from God!!". Well depend upon your faith God is actually with you already or is coming. God wouldn't be interested to come ask you what is the latest programming thing you did - His more interested in your life/soul/well being etc. Not if you made another million dollars or wrote another cool application etc.

So to end.... to use God's name is not good... remember that there are people in this world that don't like it, even if you don't beleive in God that is your choice etc and myself (and we as children of God) shouldn't judge you by it but then please be considerate and not do this.

It all comes down to being considerate to someone else's beleive etc.... in goverment / by law they call it "human rights" but in plain English its called: "being a good human being" or just "doing the right thing".

Monday, February 2, 2009

Weekly Source Code: Default Controlling Access - Be Careful!

I've a general rule where I never assume defaults in a language, I always assign an initial value to a variable for example... assuming defaults caused alot of problems for me in the past expecially in languages like C or C++ where defaults can actually "hurt" you. Each language also has a diffirent default behaviour that you will see below with Java vs C#.

One of the rules is to always provide the control access level modifier in OOP languages like Java and C# (the 2x languages that I use alot).

For example:

According to the Java tutorial on Controlling Access to Members of a Class when you don't provide an access level modifier it assumes the class and package level access only. Class access is fine since you do want a member variable to be avialable in its containing class but package level access is where it can hurt you, for example:

package com.echosystem.core;

public class SystemCall
int status = 0;
// rest of the class continue

here if you've other classes in the com.echosystem.core package those classes can directly access the status member variable above so you're not following OOP rules where encaptulation is important - not to go into too much detail but encaptulation is good! Also if you've another class in another package location you will notice that you can't access this status member variable.

Its important in this case to write the above code as:

public class SystemCall
private int status = 0;

public int getStatus()
return status;

public void setStatus(int inStatus)
status = inStatus;

// rest of the class continue

Here you see that the status member variable is private (make it encaptulated into the class) and you control access to it using a getter and setter methods.

C# will continue in the next weekly source code - I do need to give you time to think about this hey! :-)