Thursday, July 26, 2007

Pagination PHP and MySQL

I have been asked this question many times. Pagintion is a concept every programmer handles at some point of time. Yet understanding is simple, conceptual programming here varies from db to db,MySQL Provides a simple and powerful solution for this problem. Friends let us see how it is done.
Please post your comments no matter wether right or wrong. And please try to find out mistakes and fix them in the comments. as that can correct me a lot.


Hello, I am looking for a code...suppose I have 50 records in a table and I want to show them on page 10 recordes per page. Can any one give me the code? I need this code...please help me

My Answer
Assuming that u r using PHP and MySQL technologies, the solution for ur problem is `LIMIT` in select statement, limit keyword accompanies with the start and length parameters.

eg: select * from tblname LIMIT start 0, length 30;
above statement fetches 30 records starting from the first record. for your requirement these stmts might help
Pg1: select * from tblname LIMIT start 0, length 10;
Pg2: select * from tblname LIMIT start 10, length 10;
Pg3: select * from tblname LIMIT start 20, length 10;
Pg4: select * from tblname LIMIT start 30, length 10;
Pg5: select * from tblname LIMIT start 40, length 10;

now how do you automate this process?

now as u said each page needs to have 10 records.
1. so put max_recds_per_page = 10
2. next do count(*) from table to get total records say total_recds=50
3. get total_pages= total_recds/max_recds_per_page
Caution this can lead to floating digits, so ceil or make your own function that gets relevent data out of the division.
now say total_pages=5
4. now we need to display the links for the 5 pages
echo("anchor href=disp.php?start=$incr_pages ");
so the output will be
page 1
page 2
page 3
page 4
page 5

note disp.php is the display page where record navigation is required

now as the structure is ready we need to display records as we are dependent on the GET varable
start we have to validate it properly
if (isset($_GET["start"]))
now we prepare select statement to get the records from the table with the limit

$getRecds="SELECT * FROM tbl_name LIMIT ".$start." , ".$max_recds_per_page;

When the page has served fro the first time, the start variable is not set and the value for
$start will be 0

now we query the database

now we print the results in a loop


this ends the conceptual programming of page navigation or record navigation or in my terms pagination.the complete demo can be found in the attached file,

Steps to duplicate:

1. create a database called test,
2. create table as mentioned below along with the data.
3. assuming that localhost, the following demo fits in.

Test table used for this demo is

CREATE TABLE `us_states` (
`id` int(11) NOT NULL auto_increment,
`statename` varchar(50) NOT NULL, PRIMARY KEY (`id`)

-- -- Dumping data for table `us_states`--INSERT INTO `us_states` (`id`, `statename`) VALUES (1, 'Alabama'),(2, 'Alaska'),(3, 'Arizona'),(4, 'Arkansas'),(5, 'California'),(6, 'Colorado'),(7, 'Connecticut'),(8, 'Delaware'),(9, 'Florida'),(10, 'Georgia'),(11, 'Hawaii'),(12, 'IdahoState'),(13, 'Illinois'),(14, 'Indiana'),(15, 'Iowa'),(16, 'Kansas'),(17, 'Kentucky'),(18, 'Louisiana'),(19, 'Maine'),(20, 'Maryland'),(21, 'Massachusetts'),(22, 'Michigan'),(23, 'Minnesota'),(24, 'Mississippi'),(25, 'Missouri'),(26, 'Montana'),(27, 'Nebraska'),(28, 'Nevada'),(29, 'NewHampshire'),(30, 'NewJersey'),(31, 'NewMexico'),(32, 'NewYork'),(33, 'NorthCarolina'),(34, 'NorthDakota'),(35, 'Ohio'),(36, 'Oklahoma'),(37, 'Oregon'),(38, 'Pennsylvania'),(39, 'RhodeIsland'),(40, 'SouthCarolina'),(41, 'SouthDakota'),(42, 'Tennessee'),(43, 'Texas'),(44, 'Utah'),(45, 'Vermont'),(46, 'Virginia'),(47, 'Washington'),(48, 'WestVirginia'),(49, 'Wisconsin'),(50, 'Wyoming');

Tuesday, July 10, 2007

OSS Camp

OSS Camp, Delhi is the India's biggest conference, yet. Organized on the lines of Bar Camps, OSS Camps are intense events with discussions, presentations, and interactions with the participants. Motivated by the desire of learning by sharing and to share your work with the community

When & Where
The OSS Camp, Delhi is being organized on September 8Th-9Th, 2007. The Venue is yet to be decided. More info available in the Venue section.

Registrations for OSS Camp, Delhi are open. We are inviting participants from around India and overseas. You can register for the event here. If you are from outside Delhi, please help spread the word in you city or country.

Note: If you'd also like to present a session, please visit the specific Camp Site (see above) and register your session there.

OSS Camp, Delhi is a community event. There is no specific group of organizers - Every participant is an organizer. So take up the responsibility of making it a success.
If you'd like to help with organizing the camp, volunteer here and take up some task.

All details regarding sponsorship and our sponsors are available here.

Maintaining information on the Internet is not an easy task! To help us make information regarding OSS Camp, Delhi easily accessible kindly tag all your blogs, mails, posts, articles, etc with the OSS Camp, Delhi Tag, which is: OSSCampDelhiSep07

For Blogs you can also use the Track back URI: click here

1. PHP
2. MySQL
3. Drupal
4. Linux
5. PhpMyAdmin
6. Python
7. Joomla

!! Chalo Delhi SEP 8 2007 !!

Check this out for further info:

Friday, April 6, 2007

How to prepare the best Tarkari Biryani without being distracted?

Why Tarkari Biryani

Hyderabadi Biryani is a popular non-vegetarian variety of Biryani. The Hyderabadi Biryani is so named as it is seen mainly in the city of Hyderabad, India. The blending of mughlai and andhra cuisines in the kitchen of the Nizam (ruler of the historic Hyberabad state), resulted in a dish called the Hyderabad Biryani. It, like other biryanis, is made using Basmati rice which is only found on the Indian subcontinent. The spices and other ingredients remain the same, however the method of preparation involves more time.It is usually accompanied with Dahi ki Chutney, Raita or Mirchi ka Salan.

There is also a vegetarian version of the Hyderabadi Biryani in which the place of the meat is taken by a mixture of vegetables such as carrots, peas, cauliflower and potato. The vegetarian version is called 'tarkari' biryani.

My favourite biryani Video

Ingredients & Directions

1 1/2 cups Basmati Rice (i normally mix 1 cup Barsmati rice with 1/2 cup sonamasoori)

1 table spoon Oil -- or ghee

1 large Pinch Saffron-optional

1 pinch Turmeric

1/2 table ssppon Salt

2 1/4 cup Hot Water

Directions for onion mixture

1 cup Chopped Onion

2 table spoon Oil -- or ghee

1 table spoon Fresh Ginger Root -- peeled & grated

1 1/2 table spoon Cumin

1 1/2 table spoon Coriander

1/2 tea spoon Cinnamon

1 pinch Cayenne

Vegetables that you need
1/2 cup Water

1 Carrot -- diced

2 cups Cauliflower -- florets (small)

1 Green Pepper -- diced

1 Tomato -- diced

1/2 cup Peas

1/3 cup Raisins

3/4 cup Chickpeas

1/3 cup Cashew Pieces -- unsalted Salt -- to taste

In a saucepan, saute the rice briefly in one tablespoon oil, stirring to coat each kernel. Crumble in the saffron. Add the turmeric, salt, and the hot water. Bring the rice to a boil, cover the pan, and reduce the heat. Simmer for 20 minutes.
While the rice is cooking, saute the onions in the oil for 5 minutes. Mix in the ginger, cumin, coriander, cinnamon, and cayenne. Add 1/2 cup water, the carrot and cauliflower. Cover the pan and cook on low heat for 3-4 minutes. Stir in the pepper, tomato, peas, raisins, chick peas, and cashews. Continue to simmer until the vegetables are barely tender. Add salt to taste.
Mix vegetables with cooked riced. Place all in a 2-quart casserole, cover, and bake at 350 for 30 minutes.

Wednesday, January 31, 2007


Achamana And Prokshana

Achamana is sipping water three times, repeating the Names of the Lord. Prokshana is sprinkling water over ones body for the sake of purity, when a bath is not possible. This is for internal as well as external purity. While sipping water, the following Mantras are repeated: - Achyutaya Namah - prostrations to the immutable Lord; Anantaya Namah - prostrations to the unlimited Lord; Govindaya Namah - prostrations to the Lord who is known by the Name of Govinda. - Then the various Names of the Lord - Kesava, Narayana, Madhava, Govinda, Vishnu, Madhusudana, Trivikrama, Vamana, Sridhara, Hrishikesa, Padmanabha and Damodara - are repeated, touching the various parts Of the body, viz., the eyes, the ears, the face, the navel, the head, etc. One becomes pure by doing Achamana after he answers calls of nature, after walking in the streets, just before taking food and after food, and after a bath. This reminds you of the Lord now and then. Every act, every ritual, every symbol has a deep philosophical importance. They help you in changing the mental substance from Rajas and Tamas to Sattva. They give you an opportunity to think of God frequently.

The steps involved in the Rig Vedic Sandhyavandana are

  1. ShubhaArambha-Chanting of OM followed by a sloka declaring that the very thought of the Lord Pundarikaksha would cleanse internally as well as externally, whatever our dispositionmay be
  2. Achamana-Visualising the all- pervading Lord Vishnu's presence in different parts of the body and cleansing them with water symbolically.
  3. Sankalpa-Chanting of Gayathri (mentally) while doing Pranayama, a Yogic method of breathing, which enables one to strengthen and focus the mind. Then declare the intention to perform morning, noon, or evening Sandhyavandana.
  4. Marjana- meaning bath. Symbolically carried out by sprinkling few drops of water on one self while chanting sukthas calling on the Ap (Water) Devathas.
  5. Manthrachamana-chanting a mantra and drinking couple of spoons of water from the palm, intending to release all the sins -mental, verbal and physical committed during night or day, in to the energy stream of the Sun.
  6. Achamana- Same as in step no.2.
  7. Punahmarjana-Repeat bathing-while offering prayers as in 4.
  8. Papapurusha visarjana-Symbolically smelling and releasing a spoon of water, intending to release the papa purusha (negativity of our personality.)
  9. Achamana- Same as in step no.2.
  10. Sankalpa-Pranayama while chanting Gayathri mantra, and declare your intention to make morning, noon or evening offerings. (Arghya)
  11. Arghya pradana-offer a palmful of water while chanting GayathriI- Three times, symbolizing physical, mental and spiritual planes of our existence.
  12. Achamana-Same as in step no.2.
  13. Bhoothochatana-Driving out all forms of obstructions/distractions. (mentally)
  14. Asana Pranayama- Pray to mother earth, who bears every living entity on this earth, to bear us and to sanctify our asana (seat/ posture).
  15. Avahana-Pray, and invoke the Divine Gayathri, Savithri, Saraswathi, Chandarshi, Sri, and Bala, to merge in to us.
  16. Sankalpa-Pranayama with Gayathri followed by declaration to engage in Gayathri Japa.
  17. Digbandhana-Pray to Brahma, Vishnu, Rudra, Sathya, Jnana, to create a shield preventingdistraction from all directions, and protect against all negative entities.
  18. Dhyana and japa- Visualise Mother Gayathri, and repeat the mantra the pre decided no. of times. Dhyana means to remain fixed to one thought-Gayathri.
  19. Digvimochana-Pray and dismantle the shield created as in 16. (mentally)
  20. Upasthana-This consists no of mantras and slokas conveying reverence to various Deities, and seeking their blessing.
  21. Abhivadana-Identifying one's Gotra, Vedashakha, and prostate to the Divine.
  22. Achamana-Same as in step no. 2
  23. Bhagavadarpana-Dedicate the entire act of Sandhyavandana and appeal to the Divine to accept all, including short comings/lapses.
  24. Achamana- Same as 5.

Article Source:

Rate This Post

trying to put some star ratings, service links like technoratti and ... do u think this would work? comment it.

what is this for?

i will try to put some public poll afert some time