Posted in: mysql |11 Feb 2013
One frequently needs to export some MySQL tables along with certain queries that will work with that table for testing. Usually one only needs a subset of records from the table which will work with the selected queries, rather then the complete table. This can be required when the table contains thousands or millions of records and we do not want to export the complete data set, as this can be time consuming during import, or maybe we only want to provide the other user with some selected records for security reasons.
Say we have a simple WordPress database with a
SELECT statement like the following:
SELECT * FROM wp_posts WHERE post_status = 'draft'
If you want to only export records that will match the corresponding query above, then we can use the ‘mysqldump’ command-line utility with the ‘–where’ option.
The first SQL query most people learn is the SELECT statement with a query some thing like the following.
SELECT * FROM users WHERE id > 100
Nothing wrong with the syntax itself; but more often than not, what the user really wants is just a few columns from the table as shown in the PHP code below. Here we are only using three columns from the table. The usual practice of developers is to use the
* modifier to get all the columns from the table as it is easier then specifying individual column names. It is quicker to select all columns from a table and worry later which to actually use in the code.
Recently while working through Grunbaum and Shephards’ Tilings and Patterns, I stumbled on a wonderful piece of software for generating tilings – Taprats. Taprats is based on the age old Islamic art of constructing intricate geometric art based on radially symmetric star-like figures. The software is a Java applet that runs on your desktop and is surprisingly small in size for its features. It has a built-in library of tilings that can be used to construct many famous Islamic designs. Also, the construction of these designs is parametrized across different variables so you can modify various parameters to create different designs from the base example. Finally you can export the designs to various image formats to be used in your designs.
X-editable is a library which allows you to create editable elements on your page. It can be used with bootstrap, jquery-ui, jquery and jQuery and includes both popup and inline modes. This library is not supposed to be used in place of a standard form, but in places where in-place editing is required, such as data tables where quick editing is required.
Substring extraction of a long piece of text is a common element in web design, mostly in blogs and other CMS for displaying excerpts. The most common way to show an excerpt is to get n number of characters of the text, or
n number of words. We will explore both ways. In PHP we frequently use the
substr function. However,
substr or any of its variants does not split the text at word boundaries, keeping broken words hanging at the end. There are many ways we can prevent this, using some text adjustments. A simple one is shown here.
WordPress is one of the most deployed content management systems around. One of the main reasons is the number of plugins available and the ease with which we can use the system. It is not uncommon to find websites using tens of plugins to accomplish various tasks and functions. Wouldn’t it be nice if you could share the site content with other websites?
Read it on Smashing Magazine.
In one of my recent project requiring a CSV text file import, the data columns had to be in certain predefined positions for the program to work correctly. The import did not depend on field labels, which is obviously a wrong way to process data. It would not have been much of a concern had the CSV files been in the correct format. However, the CSV files I had had the columns in wrong positions, which required me to exchange the columns to their correct positions for the parent program to import them correctly. For a few files I’d have easily used a spreadsheet for the task, but with around 34 files it was going to be tedious. The task entailed me to write a small script which helped in the matter.
One of the main sources spammers harvest emails ids are from websites and Google. An easy way to prevent email harvesting is to not disclose email ids on your website, least not in an obvious way. If your site has a few dozen pages than you can manually scan those to see if any email id is being displayed. However, for large site with hundreds of pages it is not an easy process. One tool that can make the process easier is ‘theHarvester’.