Home » Programming

PHP include – How to Use It, With Examples

How to use PHP include

The PHP include expression allows you to import code from another file and import code from external PHP libraries. Here’s how to use it, with examples. PHP include will execute and import PHP code from another file or library.  It allows you to re-use code and work with libraries provided by others – for example, you may download a library to interact with a mapping service and wish to include it in your code. Syntax include ‘./path/to/file.php’; Simple! The include expression must be followed by the … Read more

Categories PHP

Home » Programming

JavaScript Callback Functions How-To, With Examples

JavaScript Callbacks

This article will explain callback functions in JavaScript – what they are, why they’re used, and how to use them. What is a Callback in the JavaScript Programming Language? A callback function is a function that is passed as a parameter to another function to be executed from within the second function. What are Callbacks Useful For? Callback functions are usually used to execute a function when another has been completed. This allows for easy code- reuse. A single function that accepts a callback can be … Read more

Home » Programming

jQuery vs JavaScript – Differences? Which is Better?

jQuery vs JavaScript

This article will explain what JavaScript and jQuery are, how they differ, and how/why they should be used. What is JavaScript JavaScript began life in the mid-1990s as a scripting language for adding interactivity to web pages. Over time it has been developed into a full-featured programming language, which can even be run outside the web browser (more detail on this in our Node.js article). You can also see our article outlining the differences between JavaScript and Typescript here. What is jQuery? jQuery is a library written in JavaScript. … Read more

Home » Programming

DIY Raspberry Pi/Python Powered PACHINKO [Kitchen Build]

Raspberry Pi Python Pachinko

Pachinko? Pichinko? Pychinko? I’ve been playing around with is idea for a while because… I don’t know; it seemed like a cool concept. That’s my whole motivation. Here’s a Raspberry Pi and Python-powered pachinko machine. This project is really basic, so it’s good for beginners, and the result is a lot of fun to mess with and would make a good desk ornament to fidget with or something for the kids to build on a rainy day to learn about coding and circuits and all … Read more

Home » Programming

How to Refresh the Page in JavaScript using location.reload(), With Examples

JavaScript Refresh Page

Here’s a short guide to refreshing a webpage with JavaScript, with examples. There are over 500 ways to trigger a page reload using JavaScript. All but one are unofficial or are the side effect of another behavior. Here’s how to do it properly. Using location.reload() Simply call: location.reload() …anywhere in your code to trigger a page reload. It’s that easy. What about window.location.reload() ? You may see some use: window.location.reload() This is exactly the same as using location.reload() – the window object in JavaScript is the global context, so there’s usually no … Read more

Home » Programming

Compare JavaScript Dates (Day/Minute/Hour/Before/After), With Examples

JavaScript Compare Dates

Following on from our article on adding and subtracting time from dates in JavaScript – here’s how to compare two JavaScript date objects. This article will explore comparing dates/times with different granularity levels – from dates that are an exact month to dates that fall in the same year. Using Boolean Operators Native Javascript date objects can be compared using standard boolean/comparison operators – allowing you to compare dates by checking whether they are equal, not equal, greater than, less than, equal to or greater than, or equal to or … Read more

Home » Programming

Converting to Integer with JavaScript parseInt() [Examples]

JavaScript parseInt

This article will show you how to use the parseInt() function in the JavaScript programming language. JavaScript is notoriously loosely typed – meaning that variables of one type (e.g., strings of text, numerical values, boolean values) are converted to others, allowing you to perform mathematical operations on strings and silly things like that. This causes all sorts of issues – strings containing numbers may not be parsed to the expected value, and all of a sudden, you have angry clients wondering why your shiny new … Read more

Home » Programming

The MySQL/MariaDB ‘SHOW INDEX’ Statement, With Examples

MySQL SHOW INDEX

This article shows you how to use the MySQL SHOW INDEX statement to list the details of indexes and keys in a table. To use the SHOW INDEX statement, you will need to know which database and table you wish to view index information for. Looking to list the databases and tables on your system? What Are Indexes? Indexes are a tool that allows a database to quickly lookup data in a table for a certain column. Usually, when searching a table, the database software must read every row in … Read more

Home » Programming

The MySQL/MariaDB ‘DISTINCT’ Statement, With Examples

MySQL Distinct

The MySQL DISTINCT operator returns only unique values from a column from a database table; duplicates are not returned.  Here’s how to use it. The DISTINCT operator can be useful in many scenarios; for example, you may want to generate a list of countries you have shipped to, or you may want to provide a drop-down menu containing unique product options for the user to select. Example Usage of MySQL DISTINCT Examples will use the following table: table_orders: order_id shipping_country product_category 1 Australia soap 2 China … Read more

Home » Programming

The MySQL (and Maria DB) TRUNCATE Command, With Examples (And Warning!)

MySQL Truncate

MySQL (and its functional equivalent, MariaDB) have two things named TRUNCATE – so watch out which one you want to use or suffer dire consequences! This article outlines the difference and usages of the MySQL TRUNCATE function and TRUNCATE TABLE statement – they share similar names but do very different things. TRUNCATE Function – Truncating a Number to a Certain Number of Decimal Places First, the TRUNCATE function. The TRUNCATE function reduces the number of decimal places for a given number. MySQL TRUNCATE Function Syntax TRUNCATE(number, decimals) Note that: number is a number decimals is an integer … Read more