Wednesday 9 June 2010

A Good use of RowCount in SQL Server 2005 and 2008

If you are in a situation where you want to limit the number of rows return for a given query just use Rowcount. Easy!

For example you have a scenario where you want only to show the 8 most recent orders out of 25 orders. So you can just set the rowcount to 8 and this is what will be returned.

NOTE: Then don't forget to set the RowCount back to 0 to reset it.

SET ROWCOUNT 3
-- Get list of orders
SELECT OrderID, DateCreated, DateShipped,
Verified, Completed, [Cancelled], CustomerName
FROM Orders
ORDER BY DateCreated


In this SQL query above, only the 3 records will be returned. And then to reset the RowCount just type:

Set ROWCOUNT 0

This will reset the ROWCOUNT for the query.

Easy isn't? Just try it!

Cheers!

Saturday 10 April 2010

How to generate random passwords for PHP users.

Hey guys.

I have a script that I'd like to share and it is about generating random password. You can very well use this script for your new user registration. And then mail it to them.

This is useful when people create accounts and have easy to remember passwords but passwords shouldn't be easy to guess. Therefore, this script is going to output something that will be hard for user to guess.

Here it is:

function GeneratePassword($min = 5, $max = 8) {
$ValidChars = "abcdefghijklmnopqrstuvwxyz123456789";
$max_char = strlen($ValidChars) - 1;
$length = mt_rand($min, $max);
$password = "";
for ($i = 0; $i < $length; $i++) {
$password .= $ValidChars[mt_rand(0, $max_char)];
}
return $password;
}
echo "New Password = " . GeneratePassword()
. "\n";
echo "New Password = " . GeneratePassword(4, 10) . "\n";




Now all you have to do is call this function and you are there!

Enjoy!

How to Set an upload limit in PHP for a file.

Alright guys here it is. Very straight-forward.

I will this with you. It may be easy to locate but most of the people aren't aware of it. So here it goes.

All you need to do is locate and open you php.ini file and just look for this word:

upload_max_filesize

It will look something like this:




And in this figure the upload limit is set to 2 Megabyte. You can set any limit you want. You can increase it or decrease the limit.

Its your choice depending upon the server capability and network traffic you have over the server.

Enjoy and leave your comments down below.

Thanks!

How to Enable/Disable Image upload in PHP

Hey Guys as promised I have yet another tip to share with you.

In this post I am going to talk about how we can disable the file upload in PHP. It is fairly we simple.

All you have to do is just open up you php.ini file and locate the word:

file_uploads

As shown in the image below:



Now you can turn it On or Off.

If you turn it off the server will not accept any file uploads. Its that simple!

Enjoy!

Sunday 4 April 2010

New Cool stuff in Javascript!

Hey guys, today I learned some new stuff in Javascript. I am gonna share 'em with you later on.

Just keep tuned in as they are pretty cool stuff.

Cheers!

How to check if a file exists in your Web Server!

One thing I came across which was quite interesting was to check if a file exists before we do any operation on the file itself.

We do that by using a php function and we do that by:

if (file_exists('file.txt')) {
print 'OK, file.txt exists.';
}

Alright this is pretty much self-explanatory, here what we are doing is checking if the file exists or not. And if does, we simply print the message. You can simply use this function in your programs before working with the file otherwise this might throw an error if the file doesn't exists.

Very simple!

Making a String Uppercase, Lowercase, or Capitalized!!

Ok in this post I am going to show you how to Uppercase, Lowercase, or Capitalize a string or a word, I mean, making a work UPPERCASE or lowercase or Capital Word. Hmm now I guess I got things much clearer for you.

Now we'll first start with uppercase, the way we do that is:

$string = "heY hOw arE yoU doinG?";
echo strtoupper($string);
// Displays "HEY HOW ARE YOU DOING?"

What we did here is we used a PHP function called string to upper or strtoupper()

Likewise, we have the string to lower i.e strtolower()
echo strtolower($string);
// Displays "hey how are you doing?"

And yes, of course, we have the last one... called Uppercase. What this will do is uppercase everything:

$string="hoW ARE yOU doInG?";
echo ucwords(strtolower($string));
// Displays "Hey How Are You Doing?"

Important: Here, we have used a function ucwords() but before we did that we used the strtolower() function to lower case all the characters in the string... then.... we Capitalized the words in the string. Make sense?

I hope it did.

Enjoy and leave comments below!

How to check if a variable is null in PHP!

As we were talking about various functions in PHP, one of the functions to check if the value is null is: is_null($MyVal) and here if the values is null it will return true and false if the value is not null.

You can always go for something like: !is_null($MyVal) that way, if the value is not null then do something.

Very simple and straight forward!

Ok again, leave your comment down below.

Cheers!

How to Check if the number is numeric in PHP.

When you are working with functions in PHP and sending numeric data you always might want to check if the number passed is an integer.

We do that by using an built-in function and that is is_numeric($MyNum) here $MyNum is a variable that is passed to this function and we can always have if-else condition i.e it will return true if numeric or false if not numeric or vice-versa.

If you take a look at the php documentation, there are plenty of functions that you can look into.

I just thought of sharing this one with you. coz this one is very simple and it can save a lot of time trying to figure out what went wrong if the user has sent data in an incorrect format.

Cheers!

And don't forget to leave comments down below

What is cURL?

First of all, I am gonna talk about what cURL is then I will tell you what it does.
cURL is an extension in PHP which allows your PHP server to access other websites, sending and receiving information via a URL-like protocol. (You'll most commonly use HTTP, which lets you talk to other web pages, and FTP, which allows you to upload and download files.) In practical terms, this means you can have your server imitate a web browser, go to other sites, and download their web pages into a variable of your choosing.

cURL is a vital tool for any serious online shopping cart, because it allows you to approve credit card charges and get live shipping quotes for customers. You use cURL to connect and send transaction data to another company's server. The server replies, telling you information such as whether the charge was approved or denied and why.

Please leave your comments down below about how you found this post. I am pretty sure it will help you in some way.

Saturday 3 April 2010

What is PHPinfo() ?

When you are working with PHP, this is the all important question!

Basically, this is a function, a built-in function I might add is having all the info about your web server.

It lets you know where you configuration file is stored (i.e. the php.ini file) and the version of PHP you are using.

Not only that, the information about the session variable the cookies and much more. Not to mention it also lets you know what extensions are loaded in the server. What extensions are in PHP, I will let you know in my next post.

Keep reading and keep tuned in!

Thanks!

Thursday 4 February 2010

How to Install IIS (Internet Information Server) on Windows 7

In this tutorial I will take you through various steps on how to install IIS on your Windows 7 computer.

Remember you do have built in (but not active) IIS server on your windows 7 machine but you need to install it. When I installed it on my machine it didn't ask me for a CD just copied all the necessary files from Windows folder.

Anyways just begin installing IIS on Windows 7:-

Step 1: Go to your Start menu in Windows 7 and select Control panel:


Step 2: Click on Programs.


Step 3: Select Turn Windows Feature on or off


Step 4: Select as it is shown in the screen below.



Step 5: Hit the Ok button and you will see the IIS being installed as shown on the screen.


Step 6: Open Firefox or Internet Explorer or any of your favourite browser.

Step 7: Type in the url bar http://localhost

and if now if everything went OK as it should then you should be able to see this screen.


Thanks for reading this article and please leave your comments down below.

Cheers!

Tuesday 26 January 2010

How to use Date function in PHP

Hey guys in this post I am gonna talk about using Date function.

By the way, anything ending with the brackets sign indicates that this is a function. for example Myfunction()

And I was talking about the Date function or Date() it expects the argument you pass it to be a format string, representing the style of output you would like. Each letter in the string represents one part of the date and time. H is the hour in a 24-hour format with leading zeros where required, i is the minutes with a leading zero where required, j is the day of the month without a leading zero, S represents the ordinal suffix (in this case th), and F is the full name of the month.

This is how it looks like when we have entered the required parameters ( or arguments):
date('H:i, jS F')

Cheers!

Using PHP tag in PHP file

We can always use the tag:

< ? php
echo '

This is a PHP tag

';
? >

This is a PHP tag and this goes inside a .PHP file extension.