-1

One of my column value is like 50-17-140(This value is showing the size details for the eyeglasses). This is unique for every product. So this 50 can be 45 to 60 and so on.

Is it possible to fetch these numbers(50, 17, 140) separately in PHP?

What will be code if I want to show only 50 somewhere of only 17 etc.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • [`explode`](https://www.php.net/manual/en/function.explode.php) can be used to split `50-17-140` into 3 values – Nick Apr 30 '20 at 13:07
  • 2
    Sounds like the data isn't modeled correctly. If these values are supposed to be independent of one another, store them in separate columns. Failing that, select the column and parse the string in your PHP code. – David Apr 30 '20 at 13:10
  • Thanks Nick! Can you please elaborate. – user2446600 Apr 30 '20 at 13:13

1 Answers1

0

Simple - use explode:

$value = '50-17-140';
$chunks = explode('-', $value);
$size = $chunks[0];
echo $size;

But in fact you should really think about cleaning up your database. This composed string, which is obviously stored in a single database field, should be split into three separate fields.

Let's say you want to fetch all records having 140 as the third value. If this is properly stored in a column, you will be able to just query for it.

wolfgang_rt
  • 154
  • 1
  • 7