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!
I just wanna live my life, don’t you get it?
Only God can see all of me, and He’ll surely know that I just wanna live my life.
I wanna wake up in the morning, say my prayers and sing to God. Proceed to my ‘workstation’. My workstation will consist of a curve-like table with a rotating chair, two or three computer systems, a powerful internet connection, uninterrupted power supply and an Air Conditioner.
I wanna start up my day pouring all my overnight ideas into my computer system. How? Programming.
I wanna achieve my goals, I wanna solve problems, I wanna work under no tension, I want ideas to flow from my head into my fingers and onto my laptop screen, I wanna see outputs.
I wanna hear from God the next step to always take, I wanna court His full direction, I want my heart to be set on fire for Him, till eternity. I wanna lavish praise on Him.
I just want to be lost in the world of my dreams and connect to reality.
I don’t wanna stick to this stereotyped lifestyle of lectures, lectures and lectures… Why won’t someone just allow me???
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!
M Academy
Who says Christians are not meant to be rich? Who says their businesses can’t prosper? Who believes we really have to be dubious before making headway financially and economically?
These and more are the questions M Academy aims to achieve: Business from the Kingdom standpoint.
Join M Academy now and you’ll learn that entrepreneurship in the Kingdom lifestyle pays more than others!
Venue: 3-in-1 lecture theatre, Federal University of Technology, Akure, Nigeria.
Pick something up!
This got me thinking.. Were we really programmed to do all we do? Is God a programmer? Reason is: I tend to believe some things are actually meant to be, regardless of what we do or feel. Then, did God really program us right from the beginning?
I’ve been on some JAVA and PHP projects for a while now, and I’m kinda stuck in some places. But a thought flew into my mind: Was I really meant to make headway in these projects? If yes, I can’t but succeed in the path. And if otherwise, well, the roadblock’s just getting started.
But the truth remains, if I’m so adamant to failure and I constantly refuse to be discouraged by failures, sweetheart, I’ve already made my headway! Its not all about the final result, its the fact that I refused to acknowledge that those projects were “too difficult” for me to code.
Like a wise man once said, “When we fall down, we pick something up.”
Peeps, never get discouraged in anything you do (I bet you’ve heard this a thousand and one times). Its just the truth!
Facts about Bill Gates!
Bill gates earns 250 US $ every
second, that’s about 20million a
day and 7.8 billion a year!
If he drops a thousand dollar
(almost 50,000 Rs),he won’t even
bother to pick it up bcoz the 4
seconds he picks it,he would’ve
already earned it back.
The US national debt is about 5.62
trillion,if bill gates were to pay the
debt by himself; he will finish it in
less then 10years.
He can donate 15 US$ to everyone
on earth but still be left with
5million US$ for his pocket money.
Michael jordan is the highest paid
athlete in US. if he doesn’t drink
and eat,and keep his annual
income i.e. 30 million US $ he will
have to wait for 277 years to
become as rich as bill gates is
now.
If Bill gates was a country on
earth he would be the 37th
richest country on earth
If you change all of bill gate’s
money to 1 US $ notes, you can
make a road from earth to
moon,14 times back and forth.
but you have to make that road
non stop for 1400 years,and use a
total of 713 boeing 747 planes to
transport all the money.
last but not the least:
If microsoft windows users can
claim 1 US$ for every time their
computers hang bcoz of
microsoft windows, bill gates will
be bankrupt in 3 days.
Culled from: facebook.com/Naijaolofofo
Dyslexics get it right
A friend of ours has dyslexia.
She and her family are often
travelling to different hotels. She
asked her Mum the other day:
“How come every hotel we go to
has this book called ‘Holly’s
Bibble’?”
It was quietly pointed out to her
that it was the ‘Holy Bible’. She
opened the page, saw a picture
of Christ on the cross and
looked up sad. Her Mum asked
her what was wrong and she
responded: “Not looking good
for Jesus Krist!” And then added
that she doesn’t want to be
religious.
The interesting thing about
dyslexics (and who on earth
invented such a word to
describe people who have
difficulty spelling?) is that they
often speak and spell as the
English language should be
spoken and spelt. Maybe we
dyslexics do it the right way
where as the rest of you do it
the wrong way!
Any other good stories out there
with examples of dyslexics
getting it wrong? For instance,
my Mum would always say:
“Two in the bush is better than
one in the hand.”
By Richard Branson.
Founder of Virgin Group.
Hard code
Have you ever felt discouraged while programming? Did you get to a stage where you feel there isn’t a way out? Has headache become part and parcel of you when you hit a dead-end while coding? I feel you pain, pal.
But afterwards, did you hear of a way out? Did you get to know hoe to think outside the box? Were you able to hit a lifetime solution? Are you in search of how to break out of this completely? Do you have an idea of how to soften HARD CODES? If yes, please let me know, so we can both share it.
The more you do in public…
Blog. Tweet. Comment. Email.
Engage
You must do tins dat make u
vulnerable. Tins dat bring public
scrutiny. It’s d only way you will
get noticed
Tinkin u can release a product
while hiding in a dark corner is a
common mistake, and a recipe 4
failure. Even if u delete ur blog in
3 months, or start a new Twitter
account, wit every action u take
beat back dat terror u experience
d 1st tym u try anytin.
Publish a blog post evry week.
Tweet 5 times a day. Comment on
3 blogs a day. Email bloggers
whom u admire just 2 tel dem.
Engage wit anyone who contacts
you.
You’ll find that once u start
engaging other people, things will start to
move.