Latest Post

Error: No input file specified.

While trying to run a codeigniter app the other day I came across this error just after I had finished uploading the files and making the ne...

Wednesday, October 7, 2009

Example: mysql update with inner join

UPDATE product
INNER JOIN product_price
ON product.productId = product_price.productId
SET product_price.price = product_price.price * 1.5
WHERE product.dateCreated < '2009-10-23'

NOTE: This applies to MySQL version 4.0 or higher

Friday, June 26, 2009

Javascript: search for a string withing another string

//In this example i'm using regular expressions

var myRegExp = /find me/;
var string1 = "can you find me in this string?";
var matchPosition =;

if(matchPosition != -1){
//match was found on position matchPosition
//not found in string

Tuesday, June 2, 2009

How to print the contents of a php page into a variable

// To get the generated HTML
$source = file_get_contents("");

// To get everything including PHP source
$source = file_get_contents("/path/to/script.php");

Thursday, May 28, 2009

Incorrect usage of UNION and ORDER BY

A common problem when using the UNION command in MySQL is when you want to order the sets of data differently. If you do it incorrectly, you will see the error message:

Incorrect usage of UNION and ORDER BY

To solve the problem, wrap each individual SELECT statement in brackets as shown below:

(SELECT * FROM table1)
(SELECT * FROM table2)

Monday, May 25, 2009

How to group by a datetime field in mysql

SELECT YEAR(datefield) Y, MONTH(datefield) M, DAY(datefield) D FROM yourtable
GROUP BY DAY(datefield)

Tuesday, May 19, 2009

PHP: Calculate Number of days between dates

Now that timestamps have been reviewed to show you some easy way to take two days and return a total number of days. The example below will take an arbitrary date of April 4, 2008 and May 12, 2008 (the current date I wrote the article)

$time_A = strtotime("April 4, 2008"); $time_B=strtotime(now); $numdays=intval(($time_B-$time_A)/86400)+1;

The number of seconds in a day is 86400 and the calculations usually shorts you a day so thats why we add a 1. This is do the fact the now() returns the current time which is not a complete day. 


Thursday, April 23, 2009

Close window without the prompt message in IE7

If you tried to close a window using javascript window.close() method in IE7, and as you may noticed a message will prompt "The Webpage you are viewing is trying to close the window. Do you want to close this window". Because of the security enhancements in IE7, you can't close a window unless it is opened by a script. So the walkaround will be to let the browser thinks that this page is opened using a script then closing the window as outlined below.

Create a javascript function which will be called to close the window

function CloseMe(){'','_self','');

The code in bold is used to open a window in this case it's not defined into the current window. In this way, we let the browser thinks that the current window is opened using javascript, so when the window.close() is executed it will close it without the message being displayed.

You can now close the popup window by calling the CloseMe() function at the point where you want to close your page.

Hope this helps

Wednesday, April 8, 2009

mysql 'not a valid result resource' errors

Here's what's going on with 'not a valid result resource' errors. Take the following example:

PHP Code:
 $query 'SELECT * from table';
$result mysql_query($query);
$row mysql_fetch_array($result))
   { echo 
$row['foo']; }  
In the above, the mysql_query() function is sending the specific query to the database and returning a 'resource identifier', which is being set as the value of $result. These are not the results themselves -- if you echo $result at this point, you'll get 'Resource id #x'. The mysql_fetch_array() function in your while loop takes this resource identifier and creates an array of the actual db contents that you can use.

If your mysql_query() function fails to get a resource id, it returns a boolean FALSE instead. FALSE, of course, isn't a resource identifier, so when you try to pass it to mysql_fetch_array(), it will cough up the 'not a valid result resource' error. So all of you are getting failures in your mysql_query() function.

Using 'or die(mysql_error())' at the end of your mysql_query() call, will, instead of setting $result to FALSE, kill the script and, more importantly, return a more descriptive error message. 

Probably 80%+ of the time, a failed mysql_query() is caused by a syntax error in the query itself. Be especially mindful of any variables you're using in your query -- if they're not being set correctly, they can cause a syntax error. A failure to connect to the database can also cause mysql_query() to fail, so keep that in mind. Either way, the mysql_error() function will give you more information.

Thursday, April 2, 2009

My popular readings of the week

Microsoft Preps Open-Source Apps Marketplace
Microsoft is in the process of building out a marketplace for open-source applications that could work like an equivalent to an app store for applications, services and support for open-source technology that runs on the Windows platform. At MIX09, Microsoft released several components of the Microsoft Web Platform, an integrated set of tools, servers and frameworks that work seamlessly together and interoperate with popular open-source applications and products that are used in the community. Microsoft is looking at Windows Azure as a potential distribution platform for these applications. read more ...

Microsoft Open Sources .NET MVC Framework
Further evidence of Microsoft's growing commitment towards interoperability and open source — the ASP.NET MVC source code has been released under the Microsoft Public License (MS-PL). read more ...

Highly anticipated open-source releases coming in '09
When big companies release new software, they launch it with lots of hoopla: press tours, technical conferences, free T-shirts. Open-source projects, even the well-known ones, generally release their major new versions with a lot less fanfare. The FOSS (free and open-source software) community is often too busy coding and testing to bother with marketing, even when the new "point release" of the software is really remarkable. read more ...

More Stories

Chitika Ads