. Rising Code Challenges Skip to main content

Posts

Showing posts from May, 2017

Fetch random results form MySQL

If you read the MySQL manual you might have seen the ORDER BY RAND() to randomize the the rows and using the LIMIT 1 to just take one of the rows. SELECT name FROM random ORDER BY RAND() LIMIT 1; The reason that ordering by RAND() can be slow is that you're forcing the database to actually sort the whole table before returning anything. Just reducing the load to a single table scan is much faster (albeit still somewhat slow). SELECT name FROM random AS r1 JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM random)) AS id) AS r2 WHERE r1.id >= r2.id ORDER BY r1.id ASC LIMIT 1

HTML DOM Manipulation using JavaScript

Manipulate HTML input objects using JavaScript[/caption] JavaScript is a lightweight , interpreted , object-oriented language with first-class functions , and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well. Today we will discuss about creating theme using javascript. JavaScript runs on the client side of the web, which can be used to design / program how the web pages behave on the occurrence of an event. Javascript can access and manipulate HTML input objects, and this is basics to create a theme using javascript. Change Body Background Color <html> <head> function changeBodyColor($color) { document.body.style.backgroundColor = $color; } </head> <body> <button onclick="changeBodyColor('red')" >Red</button> <button onclick="changeBodyColor('green')" >Green</button> <button onclick="cha...