Get browser window size using jQuery (useful for responsive web design)

I am sharing a very useful bit of code I use to get the window width when making responsive sites.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get browser window size using jQuery (useful for responsive testing)</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(window).bind({
load:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
resize:function(){
var windowSize = $(window).width();
$('p.window-width').text('Window width = ' + windowSize + 'px');
},
});
</script>
</head>
<body>
<h1>Resize your browser window to get width:</h1>
<p class="window-width"></p>
</body>
</html>

view raw
responsive.html
hosted with ❤ by GitHub

Please comment below if you have any better solution.

Debug WordPress White Screen of Death and other Errors

After so many requests asking about “WordPress white screen of death”, I would like to quickly share my strategy I use in most of the WordPress installs I manage which allow me to quickly switch on debug mode when required.

In the file wp-config.php, which can be found in your WordPress root, search for variable WP_DEBUG and replace it with

if (isset($_GET['debug']) && $_GET['debug']=='debug_mode') {
    error_reporting(E_ALL); ini_set('display_errors', 1);
    define('WP_DEBUG', true);
}

Now you can open any page, and if something goes wrong there, like a white screen of death, you can add ?debug=debug_mode to the end of its URL and check what’s causing the trouble. Eg. http://www.mywordpresssite.com?debug=debug_mode

I hope this helps.

Export MySQL to Excel (.xls) using PHP

The below code will export every column name and value from your database into an excel document (.xls).

<?php
/***** EDIT BELOW LINES *****/
$DB_Server = "localhost"; // MySQL Server
$DB_Username = "username"; // MySQL Username
$DB_Password = "password"; // MySQL Password
$DB_DBName = "databasename"; // MySQL Database Name
$DB_TBLName = "tablename"; // MySQL Table Name
$xls_filename = 'export_'.date('Y-m-d').'.xls'; // Define Excel (.xls) file name
/***** DO NOT EDIT BELOW LINES *****/
// Create MySQL connection
$sql = "Select * from $DB_TBLName";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Failed to connect to MySQL:<br />" . mysql_error() . "<br />" . mysql_errno());
// Select database
$Db = @mysql_select_db($DB_DBName, $Connect) or die("Failed to select database:<br />" . mysql_error(). "<br />" . mysql_errno());
// Execute query
$result = @mysql_query($sql,$Connect) or die("Failed to execute query:<br />" . mysql_error(). "<br />" . mysql_errno());
// Header info settings
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$xls_filename");
header("Pragma: no-cache");
header("Expires: 0");
/***** Start of Formatting for Excel *****/
// Define separator (defines columns in excel &amp; tabs in word)
$sep = "\t"; // tabbed character
// Start of printing column names as names of MySQL fields
for ($i = 0; $i<mysql_num_fields($result); $i++) {
echo mysql_field_name($result, $i) . "\t";
}
print("\n");
// End of printing column names
// Start while loop to get data
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result); $j++)
{
if(!isset($row[$j])) {
$schema_insert .= "NULL".$sep;
}
elseif ($row[$j] != "") {
$schema_insert .= "$row[$j]".$sep;
}
else {
$schema_insert .= "".$sep;
}
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>

view raw
export.php
hosted with ❤ by GitHub

Note: Delete the line spaces if you receive a parse error.