Programming Tips & Insights

jQuery: How to check if an element has a particular class

To know whether a class exists on an element with jQuery, you need a simple test method: is(). For example, to test if an element #elm has the class ‘first’: if ($(#elm).is(‘.first’)) { //#elm has the class } else { //#elm doesn’t have the class } jQuery is() is the function that checks if any …

jQuery: How to check if an element has a particular class Read More »

jQuery: How to test or check whether an element exists

.length property in JavaScript returns the length or number of elements inside an array or the string length. While jQuery selector mechanism $(“elm”) returns an array of DOM objects (such as elements), you can also get the number of the length of the returned objects array by: $("#some").length To check the existence of the element, …

jQuery: How to test or check whether an element exists Read More »

jQuery: Selecting elements with uncommon / special characters in ID or class name

HTML generated by some CMS or frameworks include elements with rather uncommon characters in ID or class names. For example, some may have special characters such as ‘.’ or ‘[..]’ in the ID or Class. To work around this, a selector in jQuery should be written this way: $(“$some.id”) // won’t work for ID: some.id …

jQuery: Selecting elements with uncommon / special characters in ID or class name Read More »

MySQL: id BETWEEN start AND end Instead of LIMIT start, step For Better Database Performance

Suppose you have a ultra large table of 1 million records and you need to page all those records across 10,000 web pages with 100 records on each page. For page 2, the most straightforward approach is undoubtedly: SELECT * FROM table LIMIT 100, 100 However, this query would introduce performance issues when the starting …

MySQL: id BETWEEN start AND end Instead of LIMIT start, step For Better Database Performance Read More »

SQL: Randomly Shuffle Rows or Records – Reorder them in a random order

Easier than it appears. Just create a new table and import all those rows and records random selected and ordered by the RAND() SQL function: CREATE TABLE new_table SELECT * FROM old_table ORDER BY RAND() Of if you have created a table identical to the structure of the old one, use INSERT INTO instead: INSERT …

SQL: Randomly Shuffle Rows or Records – Reorder them in a random order Read More »

PHP: Return and Get the Last Letter / Character of a String

To get the last character of a string in PHP, you need a combination of the functions of substr() and strlen(). For example, you need to get the last digit of a date string such as ‘Feb. 3’ or ‘Aug. 14’ to determine whether the trailing of the date will be ‘st’, ‘nd’, ‘rd’ or …

PHP: Return and Get the Last Letter / Character of a String Read More »

Incisive Software Engineering & Programming Quotes and Sayings

” If debugging is the process of removing software bugs, then programming must be the process of putting them in. “ – Edsger Dijkstra ” Rules of Optimization: Rule 1: Don’t do it. Rule 2 (for experts only): Don’t do it yet. “ – Michael A. Jackson ” The best method for accelerating a computer …

Incisive Software Engineering & Programming Quotes and Sayings Read More »

The Best Online Domain Name Availability Checker Tool (AJAX)

As if there’s an offline one to check whether a domain is available or not. 😉 Psychic Whois is it. It’s the best domain availability checking tool I know so far. AJAX powered, it instantly checks whether a domain is available for registration after you have typed the primary part by listing all 6 popular …

The Best Online Domain Name Availability Checker Tool (AJAX) Read More »

Free Online Skills Test for Freelance Web Developers and Programmers: PHP, MySQL, (X)HTML, CSS, JavaScript and More

There are plenty of freelancing jobs sites and outsourcing interactive platforms between service providers and clients now. Elance is probably the most renowned online freelance jobs brokerage firm. Why? Google tells me. 😉 Elance has the largest bunch of backlinks according to Google via query “link:elance.com”, over 2,400 as of now, the most prominent in …

Free Online Skills Test for Freelance Web Developers and Programmers: PHP, MySQL, (X)HTML, CSS, JavaScript and More Read More »

PHP: Generating Summary Abstract from A Text or HTML String, Limiting by Words or Sentences

On index or transitional pages, such as homepage or category pages of WordPress, you don’t want to show the full texts of your deep content pages yet but just a content snippet of the first few sentences or words as a summary with a read more link to the actual article. This is generally good …

PHP: Generating Summary Abstract from A Text or HTML String, Limiting by Words or Sentences Read More »

JavaScript: Show & Tick a Specific Local Time Clock (Fixed Time Zone) instead of Client Time

When I’m coding for a new sub site where I need to show the local time of mine and my developers’ wherever the visitors are. Things get a little bit more tricky. Time basics in JavaScript and PHP To offset time zone differences in calculation, both JavaScript and PHP specs have time stamps representing the …

JavaScript: Show & Tick a Specific Local Time Clock (Fixed Time Zone) instead of Client Time Read More »

PHP: Checkbox Array in Form Handling – Multiple Checkbox Values in an Array

Checkboxes is probably one of the most frequently used form controls which come handy in dealing with one to many relationships. The multiple selective nature of HTML form checkboxes require a convenient way for PHP to process multiple checkbox values, ideally in a single array. By default, each and every HTML input control including checkboxes …

PHP: Checkbox Array in Form Handling – Multiple Checkbox Values in an Array Read More »

PHP: Escape String Literals for SQL, mysqli::real_escape_string and PDO to Prevent SQL Injection Attacks

To successfully run a query with text data containing single quotes ‘ as well as other SQL reserved punctuations, AND to prevent SQL injections, you will always want to escape the text values before using them in a SQL query. In PHP 4.0, we are stuck with mysql_real_escape_string. With PHP 5.0, mysqli:prepare and mysqli::real_escape_string are …

PHP: Escape String Literals for SQL, mysqli::real_escape_string and PDO to Prevent SQL Injection Attacks Read More »

PHP: Prevent SQL Injection Attacks

SQL injection is a typical code injection attack that exploits weaknesses of application in the database layer. SQL injection vulnerability is created when one scripting or programming language is embedded in or used as input in another with failure to verify the legality or filter for potential dangerous codes. SQL injections are possible when input …

PHP: Prevent SQL Injection Attacks Read More »

Scroll to Top