My Codes, Webmasters - by Yen on Saturday, November 27, 2010 17:36 - 0 Comments
Bookmarklets to Easily Select phpMyAdmin Tables

For those who had used phpMyAdmin, I think we would all agree that it is one of the indispensable tools for web developers. However, there is still some features that I felt is lacking from phpMyAdmin. Dropping multiple tables with wildcard matching.
As we all know, web hosts sets limits on the number of database you can have in a shared web hosting environment. Sometimes this limitation forced developers to have scripts sharing the same MySQL database. For example, a Joomla! CMS site with integrated phpBB forum. Then we would have table names with prefixes to differentiate Joomla! tables (jos_) and phpBB tables (phpbb_).
All this is fine until one day I decided to change to another forum script and remove phpBB. Deleting the files is easy but how do I delete the tables? There is no MySQL command for DROP TABLE LIKE ‘tableName_%’. Other options are such as creating a procedure, multiple MySQL commands, and other methods that require SSH access. My choice is to use phpMyAdmin. But clicking on each phpbb_ table checkbox is tedious work and I need to make sure there are no accidentally selected jos_ tables. And so I decided to write some bookmarklets to help me do it properly.
Bookmarklet 1:
Javascript snippet for selecting tables through regular expressions (Javascript flavour obviously).
Example: To select phpBB tables, I would enter phpBB_ at the prompt.
// Add jQuery
if (typeof jQuery == 'undefined') {
var jq = document.createElement('script');
jq.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild(jq);
}
// Select tables
var rxObj = new RegExp(prompt('Select tables by regular expression:'));
$(':checkbox[id^="checkbox_tbl"]', window.parent.frames[1].document).each(function() {
if (rxObj.test($(this).val())) {
$(this).attr('checked', true);
}
});
Bookmark This
Bookmarklet 2:
Javascript snippet to toggle selections.
// Add jQuery
if (typeof jQuery == 'undefined') {
var jq = document.createElement('script');
jq.setAttribute('src', 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild(jq);
}
// Toggle Selections
$(':checkbox[id^="checkbox_tbl"]', window.parent.frames[1].document).each(function() {
$(this).attr('checked', !$(this).attr('checked'));
});
Bookmark This
For readability, these Javascript snippets has not been minified. But it’s just a short snippet and so I don’t think minifying it will make any real difference. For those who are interested, I am sure converting these scripts to a GreaseMonkey script would not take too much work.
Credits to jQuery and Moxley Stratton’s Bookmarklet Compiler
- Lelong Utilities (Greasemonkey Script)
- New Nitro-charged Firefox 3.5 Released
- Programmer Caste System



Got something to say?