Another Project Done!

#Sighs

Started this project back in June (I guess, or late April), came up with the Version 1.0 around June 15th or so, purely PHP.

You know the funny thing about my coding, I’m not a fan of creating too many pages, all in a bid to add more functionality.  This made me to embrace AJAX, and trust me, it was fun.  Apart from that, I learnt a new thing from PHP: using buttons instead of pages. If you know this trick, I bet you your whole website can be just one page (or max. of 2, depends).  It was amazing writing a single function for so many buttons and they end up firing events for you.

Using AJAX + the jQuery library enabled me to bypass a lot of redirects I used to do when I wanted to catch exceptions.  Now, my exceptions are caught right when the user is typing (or when the cursor is on the next field).

I released the Version 2.0 on the 21st of July, 2013, and it was sweet… The look, the feel,… I was proud of it. User-friendly, and a lot.

Talking about the SQL, it was a different matter altogether. Tables performing different functions to complement each other, and writing to external text-files to keep track of record and changes.  The whole project was a bomb!

You know the fulfillment after writing over a thousand lines of codes (PHP, JavaScript, AJAX: my favourites), sleepless nights, mental stress, “coding dehydration” (bet you haven’t heard that before), what about 10 different SQL tables all performing different functions, yet keeping connected data?

A quick one: Learn how to use cool music to accompany you in the unending journey of programming, my secret.Popoola Abimbola

Version 3.0 is on the way, and I’m pretty sure you can’t wait to see “advancement in technology”, I can’t wait also!

#smiles

AJAX vs pure PHP

First things first: It’s been a while I posted about Programming.

Second things second: The topic sounds weird, because jQuery and PHP are two languages with different purposes.

In my line of coding, I’ve discovered its too naive of programmers to be ‘troubling’ the server every time. How? Simple! You want to check if a record exists in a database, you go through the server.  You want to validate, the same procedure. And so on..

JavaScript, jQuery, AJAX… all came to solve part of these problems.. hence, I’ll be recommending swapping PHP for jQuery once in a while.

Recently, while working on a mega project, I wanted to capture an exception of duplicate signup. This gave me a lot of headache (you might think its an easy and straight-forward task, you’re not wrong).  I eventually made a headway when I rubbed minds with jQuery.

To check if a record exists in your database, you set the following:

$(document).ready(function(){
$(‘#username’).keyup(username_check);
});

//this gets the function ready with name ‘username_check’ and parameter ‘username’

Afterwards,

function username_check(){
var username = $(‘#username’).val();

if(username == “” || username.length < 4){
$(‘#username’).css(‘border’, ‘3px #CCC solid’);
$(‘#tick’).hide();
}else{

jQuery.ajax({
type: “POST”,
url: “check.php”,
data: ‘username=’+ username,
cache: false,
success: function(response){
if(response == 1){
$(‘#username’).css(‘border’, ‘3px #C33 solid’);
$(‘#tick’).hide();
$(‘#cross’).fadeIn();
$(“#AssignTPM”).attr(“disabled”, “disabled”);
}else{
$(‘#username’).css(‘border’, ‘3px #090 solid’);
$(‘#cross’).hide();
$(‘#tick’).fadeIn();
$(“#AssignTPM”).removeAttr(“disabled”, “disabled”);
}

}
});
}

}

//the lines above set the event to fire if the record exists or not. Also, it loads two images: ‘tick’ and ‘cross’ – tick for non-existence and cross for otherwise.

It also disables the submit button, so that users cannot submit invalid data but enables it when input has been validated.

‘check.php’ is the php file that queries the database for the existence of the record. The contents are these:

$username = trim(strtolower($_POST[‘username’]));
$username = mysql_escape_string($username);

$query = “SELECT username FROM usernameCheck WHERE username = ‘$username’ LIMIT 1”;
$result = mysql_query($query);
$num = mysql_num_rows($result);

echo $num;
mysql_close();

You can thereafter go ahead to add designs in the homepage. In may case, this is what I have:

<style>
#username{
padding:3px;
font-size:18px;
border:3px #CCC solid;
}

#tick{display:none}
#cross{display:none}

</style>

The ‘display:none’ makes sure that the two images ‘tick.jpg’ and ‘cross.jpg’ are not displayed by default.

Note: include the two images immediately after the field you’re validating, like this:

<img id=”tick” src=”tick.png” width=”16″ height=”16″/>
<img id=”cross” src=”cross.png” width=”16″ height=”16″/>

Doing this, you’ve successfully bypassed the headache of pestering the server!

Stupid, Inconsistent, Smart or Sound-Smart?

While doing a head count of what I do and what I’m good at.. I got this list:

Programming Languages

QBasic, Visual Basic, Fortran77, Fortran90, C, Java, PHP, SQL

Design Softwares

Photoshop, Fireworks, etc

Now, streamlining it down to the ones I use mostly:

JAVA, PHP & SQL.

My destination:

A lot of dudes have this same problem (though I don’t know if its really a problem though), you know that feeling when you seem to be ‘gifted’ in so many areas, and what follows? Indecision!

Imagine having an interview and you’re asked “What language are you good at?”. And you go on mentioning all available ones on planet earth.  Dude, you’re so not it! The question was “”What language…?” not “What languages…?”.  This has really been a stumbling block in some people’s lives, I’m not excluded.

Solution? So simple! There’s always a favorite, no matter the number of available choices.  Just pick one! Be consistent with ONE, stop trying to be sound-smart, its a stupid act (permit me to say that).  Also makes you irrelevant in some cases.  You, thereafter, tend to lose some expensive chances just because of a simple “Smart”.

If you still feel being Jack of all Trades and Master of none is what pays, get a life!