Jump to content

Recommended Posts

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

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....)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.