-1

I want to build a simple Size Finder for my Fashion Online Shop.

For the beginning, let's say there are 3 Input fields for Shoulder Width, Weight and Height and a checkbox for the gender. When the user enters their values, the script should automatically search for the nearest/best matching result and return it.

Let's say the user enters the following values.

Gender: male

Weight: 75kg

Height: 170cm

Shoulder Width: 56cm

The "male" table of values ​​contains the following information.

weight height shoulder recommended size
50 155 40 XS
65 165 45 S
75 175 50 M
85 185 55 L
95 195 60 XL

I'm a bit fit in PHP and JS but don't want to use a database and somehow solve that with (multidimensional?) arrays and I haven't the faintest idea how to make the script search within multiple values ​​for the closest one, using some sort of priority system for certain thresholds. What would you recommend as the best approach here? Somehow I have the feeling that I am overlooking a logic error or at least not paying attention to something that can lead to problems later...

Bill Bronson
  • 511
  • 2
  • 9
  • 22
  • 2
    This question is incomplete in two ways: 1. You need to better define the algorithm you want to use, the storage is not the problem, and 2. it is very much appreciated if you make, at least, an attempt as solving your own problem. Just asking us to write the code for you is not what this site is about. – KIKO Software Jun 02 '22 at 15:09
  • Ehm... 1. I have no idea which algorithm I want to use because I don't know which ones exist and how to use them at all. I haven't even got that far yet and 2. I didn't ask to write this for me but only asked how other coders would approach it and whether my approach without a database and with arrays really makes sense... – Bill Bronson Jun 02 '22 at 15:15
  • 2
    OK, I understand. What I meant with the algorithm is something like this: What size does someone get if they weight 70 Kg but have a height of 190 cm? We cannot decide this for you, it's something you need to work out yourself. Oh, an array, for the little amount of data you have, makes far more sense than a database. It also doesn't need to change, so that again point to an easy fixed array of data. – KIKO Software Jun 02 '22 at 15:18
  • Yes, that is exactly what I meant by the "priority system". Somehow it should become clear that if the value: "Size" is above a certain key figure, it must always jump to the corresponding size. As an example: If you weigh only 55kg but are 190cm tall, the size "S" must be excluded and the orientation must go in the direction of the next larger value. – Bill Bronson Jun 02 '22 at 15:23
  • 2
    You probably know more about clothes sizes than we do, but think of "weight", "height" and "shoulder" as the axis of a 3D space. Your "recommended sizes" occupy a volume in that space. You need to define that volume and decide what to do when the volumes overlap. – KIKO Software Jun 02 '22 at 15:26
  • This is the food for thought I needed. :) <3 – Bill Bronson Jun 02 '22 at 15:28
  • 2
    You could, for instance, when the volumes overlap, say: You can choose either 'M' or 'L'. – KIKO Software Jun 02 '22 at 15:28
  • So I need a method with which I can set up some kind of scoring system? As an example the user values: W56,H171,S49 - The weight "56kg" is closest to the recommended value for "XS" but the height is closest to "M" and the shoulder width as well. Thus, 2 values give a higher priority to size "M". Is it possible to approach it this way? – Bill Bronson Jun 02 '22 at 15:39
  • 2
    I'm viewing it more as a mathematical problem. You have 3D space, with dimensions "weight", "height" and "shoulder". In it you can define a line, for instance for size XL using two "perfect" fitting points (your table has only one). The customer will be a point in that 3D space, and you can [compute the distance from that size-line](https://stackoverflow.com/questions/15881718/perpendicular-distance-from-a-point-to-a-line-represented-by-two-points). You can do this for all sizes, and the size-line the customer is closest to is the right size. – KIKO Software Jun 02 '22 at 15:55
  • 1
    Perhaps lines are not ideal, you could simply use the points, from your table, in the 3D space and compute the distance with the [Pythagoras' Theorem](https://www.mathsisfun.com/geometry/pythagoras-3d.html). That way you don't have to invent a second point. You should also apply weights to the dimensions, simple multiplication factors, otherwise length will get too dominant in the final result. – KIKO Software Jun 02 '22 at 16:03

0 Answers0