Here is the scenario 1.
I have a table called "items", inside the table there are 2 columns, e. d. item_id and item_name . I store my data this way: item_id | item_name
Ss001 | Shirt1 Sb002 | Shirt2 Tb001 | TShirt1 Tm002 | TShirt2
... etc., I store this way: the first letter is the code for the clothes, i.e. for a shirt, T for a t-shirt the second letter is the size, i.e. for small, m for medium and b for large Let's say in my table of items I received 10,000 items. I want to quickly find, I will say that I want to find a specific shirt, can I use:
Method1:
SELECT * from items WHERE item_id LIKE Sb99;
or should I do it like:
Method2:
SELECT * from items WHERE item_id LIKE S*;
* Save the result, then do a second size search, then a third identifier search. Like the concept of a hash table. What I want to achieve, instead of finding all the data, I want to first minimize the search by searching for the clothes code, following the size code, and then the id code. Which one is better in terms of speed in mysql. And which one is better in the long run. I want to reduce traffic and not break the database so often.
Thanks guys for solving my first scenario. But there is another scenario:
Scenario 2:
I use PHP and MySQL. Continue the story. If my table looks like this:
user_id | username | items_collected U0001 | Alex | Ss001;Tm002 U0002 | Daniel | Tb001;Sb002 U0003 | Michael | ... U0004 | Thomas | ...
I store items_collected in id form because one day each user can collect up to hundreds of items if I store as a string, i.e. Shirt1, pants2, ..., this would require a very large number of database spaces (imagine if we have 1000 users, and some elements are very long).
Would it be easier to maintain if I store in id form?
And if we say, I want to display the image, and the image name is the name of the element + jpg. How to do it? This is something like this:
$ result = Select items_collected from users, where userid = $ userid
Using php explode:
$ itemsCollected = explode ($ result, ";");
After that, matching each element in the element table, he would like to:
shirt1, pants2, etc.
Den, using a loop function, loop over each value and add ".jpg" to display the image?