‘insert if not exists’ in MySQL

An error will occur when inserting a new record in MySQL if the primary key specified in the insert query already exists. Using the “IGNORE” keyword prevents errors from occuring and other queries are still able to be run. Why? Although you shouldn’t normally attempt to insert a record without first checking if the primary… Continue reading ‘insert if not exists’ in MySQL

Creating jQuery AJAX requests to a PHP function Instead of PHP file

Use $.ajax to call a server context (or URL, or whatever) to invoke a particular ‘action’. What you want is something like: $.ajax({ url: ‘/my/site’,          data: {action: ‘test’},          type: ‘post’,          success: function(output) {              alert(output);      … Continue reading Creating jQuery AJAX requests to a PHP function Instead of PHP file

Add custom javascript files to the wordpress site

Use wp_enqueue_script() in an init hook, or if in the admin only then in an admin_menu or admin_init hook. It might look something like this (which assumes you are calling from your theme’s functions.php file; note how I reference the stylesheet directory): <?php add_action(‘init’, ‘mysite_init’); function mysite_init() { $ss_url = get_bloginfo(‘stylesheet_directory’) wp_enqueue_script(‘mysite-scripts’,”$ss_url/js/mysite-scripts.js”); } That’s the basics. Pre-defined and Multiple Dependent Scripts But let’s say you… Continue reading Add custom javascript files to the wordpress site

Group Similar Styles

This happens easily after a long development. We just declare the same styles over and over again without realising that something exactly the same is already exist. It’s good to look back the CSS code and reanalyse it, so that similar styles can be grouped together. Before h1 {padding:5px 0; font-family:verdana; font-weight:700;} #box1 .heading {padding:5px… Continue reading Group Similar Styles