Popular Posts

Nov 27, 2011

Get output in JSON format(PHP)

--
-- Table structure for table `test_table`
--

CREATE TABLE IF NOT EXISTS `test_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(20) NOT NULL,
  `sort_order` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `test_table`
--

INSERT INTO `test_table` (`id`, `title`, `sort_order`) VALUES
(1, 'Article 1', '2'),
(2, 'Article 2', '5'),
(3, 'Article 3 ', '4'),
(4, 'Article 4', '1'),
(5, 'Article 5', '3');


<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('extdb') or die(mysql_error());

$q = mysql_query("SELECT * FROM test_table");
while($e = mysql_fetch_assoc($q))
{
$output[] = $e;   
}
print(json_encode($output));

?>



OUTPUT:

[{"id":"1","title":"Article 1","sort_order":"2"},{"id":"2","title":"Article 2","sort_order":"5"},{"id":"3","title":"Article 3 ","sort_order":"4"},{"id":"4","title":"Article 4","sort_order":"1"},{"id":"5","title":"Article 5","sort_order":"3"}]

Nov 21, 2011

Sending email from localhost with php

A lot of developers set up PHP on their local machine to test server side development. Here's a little trick how to be able to send email from localhost so you can test email without any difficulty.

1. Go to your php.ini file and change SMTP = localhost to SMTP = aspmx.l.google.com and uncomment sendmail_from and put in your sending gmail address.

2. Go to cmd and type iisreset

3. In php, test it with mail("[youremail]@gmail.com", "subject", "body");


Note: This only works when sending email to google hosted email addresses.

Nov 19, 2011

Auto Delete unnecessary files

সাধারণত উইন্ডোজের start/run-এ গিয়ে %temp%, temp, prefetch, recent ইত্যাদি অপ্রয়োজনীয় ফাইল মুছে থাকি। তবে উইন্ডোজ এক্সপি ব্যবহারকারীরা ইচ্ছা করলে এক ক্লিকে স্বয়ংক্রিয়ভাবে এই অপ্রয়োজনীয় ফাইলগুলো মুছতে পারেন। এ জন্য ডেস্কটপে ফাঁকা জায়গায় মাউস রেখে ডান ক্লিক দিয়ে new/ text document-এ গিয়ে নোটপ্যাড খুলুন। নিচের কোডটি নোটপ্যাডে হুবহু লিখুন অথবা কপি করুন:
cd\
COLOR 4A
ECHO DELETE ALL TEMP FILES
C:

CD %TEMP%
RMDIR /S /Q %TEMP%
CD C:\WINDOWS\TEMP
RMDIR /S /Q C:\WINDOWS\TEMP
CD C:\WINDOWS\Prefetch
RMDIR /S /Q C:\WINDOWS\Prefetch
CD %TEMP%
CD..
CD..
CD Recent
Del /s /q *.*
এখন File/ save as-এ গিয়ে cleanpc.bat নামের নোটপ্যাডটি সেভ করুন। খেয়াল করুন, cleanpc নামের আলাদা একটি ফাইল ডেস্কটপে তৈরি হয়েছে। ওই ফাইলে দুটি ক্লিক করলেই স্বয়ংক্রিয়ভাবে অপ্রয়োজনীয় ফাইল মুছে যাবে।

Nov 14, 2011

How to validate an email in php5?

I have use ereg to validate email address. But it gives an error.
return ereg("^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$", $email);
Deprecated: Function ereg() is deprecated



PHP5 does not support ereg function.so the alternative way is to use the filter_var() function, which gives you a lot of handy validation and sanitization options.

filter_var($email, FILTER_VALIDATE_EMAIL)
If you don't want to change your code that relied on your function, just do:
function isValidEmail($email){ 
    return filter_var($email, FILTER_VALIDATE_EMAIL);
}



Nov 13, 2011

MAC startup keyboard shortcut


There are some startup keyboard shortcut  for MAC :-
1) When MAC boot up if  you press ”Options key”  Startup Manager Open.
2)  When MAC boot up if  you press "Shift key" it will be boot in  Safe Mode.
3)  When MAC boot up if  you press “C” key It will boot from Optical Disk OR (CD , DVD).
4)  When MAC boot up if  you press  “T” key it will be in  FireWire Target disk mood.
5)  When MAC boot up if  you press “N” key it will boot as netboot.
6)  When MAC boot up if  you press “X” key it force and it will boot from disk where there is no  MAC OS Startup Volumes.
7)  When MAC boot up if  you press  ““Command+V” key it will boot in  Verbose Mode.
8)  When MAC boot up if  you press  “Command+S” key it will boot in Single user Mode.