nuttycoder Posted May 25, 2007 Share Posted May 25, 2007 Hi I am building a drinks database/search site. At present I have 26 tables 1 table for each letter like drinksa, drinkb, drinkc..ect which represent a, b, c...ect I have realised this methed it not good practice as I can't search all 26 tables in one go. What I would like to do now is put all the drink a to z in one table called drinks. I would then be able to search that 1 table, this is fine I can do that without a problem. But I am haing some difficulty getting my head around the front end what I mean is on the front end of the site on the drinks page there are links to each section like a, b ,c, d, e,......x, y, z. But if all the data is in one table then all the drinks a to z would be output I know I can limit how many to output but I was wondering is it possible to limit by starting letter For example when a user clicks "A" then all the drink starting with "A" are output but not any other drinks starting with a diffrent letter. This would be done by usin an sql statment I belive by using limit but am not sure if its possble to limit by letter. I have been looking at a lot of foums and so far I have not come across anything that may be of help so I though I'd ask If anyone would point me in the rihgt direction or could expmain if this is possible or a better way of doing this I would be very greatful Thanks Dave Link to comment https://forums.phpfreaks.com/topic/52937-limit-mysql-output-by-letter/ Share on other sites More sharing options...
georg Posted May 25, 2007 Share Posted May 25, 2007 I think you're posteng in the wron forum, it sems to be a question about databases.. In mysql I would do it as follows: SELECT * FROM `drinks` where left(name,1)='A' The code should make everything clear.. Link to comment https://forums.phpfreaks.com/topic/52937-limit-mysql-output-by-letter/#findComment-261424 Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 There's a 2x performance advantage by using LIKE instead of LEFT. Nearly insignificant, but I was doing this benchmark this morning anyway, and I thought I'd share it. mysql> SELECT BENCHMARK(1000000,LEFT('Aaaaaaa',1)='A'); +------------------------------------------+ | BENCHMARK(1000000,LEFT('Aaaaaaa',1)='A') | +------------------------------------------+ | 0 | +------------------------------------------+ 1 row in set (0.14 sec) mysql> SELECT BENCHMARK(1000000,'Aaaaaaa' LIKE 'A%'); +----------------------------------------+ | BENCHMARK(1000000,'Aaaaaaa' LIKE 'A%') | +----------------------------------------+ | 0 | +----------------------------------------+ 1 row in set (0.07 sec) (Just don't say the word "drinks" this morning. Ugghh....) Link to comment https://forums.phpfreaks.com/topic/52937-limit-mysql-output-by-letter/#findComment-261534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.