0

how can i get mysql results with alphabetical pagination i.e i have 2 fields i.e id and name in mysql table and following html links for pagination

A B C D E F G .......

by clicking on A i want to get results names starting with A

how can i do that with php

Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
Web Worm
  • 2,080
  • 12
  • 40
  • 65
  • Numerous duplicates: http://stackoverflow.com/search?q=php+pagination – Pekka Oct 21 '10 at 20:57
  • Possible duplicate of http://stackoverflow.com/questions/2280230/searching-for-advanced-php-mysql-pagination-script – Pekka Oct 21 '10 at 20:58

2 Answers2

3

Use SQL LIKE syntax:

SELECT * FROM tablename WHERE name LIKE 'A%'
Jacob Relkin
  • 161,348
  • 33
  • 346
  • 320
1

Use a query like

SELECT `id`, `name` FROM `table` WHERE `name` LIKE :index

Then, bind :index to something like sprintf('%s%%', $selectedIndex)

It would also be a good idea to create an index on the name column.

Phil
  • 157,677
  • 23
  • 242
  • 245