views:

32

answers:

2

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

+3  A: 

Use SQL LIKE syntax:

SELECT * FROM tablename WHERE name LIKE 'A%'
Jacob Relkin
you mean LIKE 'A%'
Junior Mayhé
@Junior, Yes. Thanks! :)
Jacob Relkin
That query wouldn't return results that start with A, but those that end with A. so: SELECT * FROM tablename WHERE name LIKE 'A%'
james_bond
@james_bond, I already updated my answer.
Jacob Relkin
Yes I saw it but I hitted 'Add comment' before seeing it
james_bond
+1  A: 

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 Brown