-1

I have a string which is combination of two cells from a mysql table

My strings are like this user_ID = 100A, 100B, 100C ...

My Mysql Table has cells value like thi USER = 100, ID = A, ....

SO I want to get result from the table using where clause like this

(SELECET * FROM table1 WHERE USER+ID = "100A" ORDER BY USER)

please tell me how to correctly use above query

Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42
Raj
  • 37
  • 4
  • What strings? where is your table format? what have you tried so far? why is there a + after USER? I highly doubt that this query works, btw SELECT* you have a typo. – Spoody Jan 30 '18 at 10:40
  • 1
    `WHERE user =100 AND id="A"` ? – B001ᛦ Jan 30 '18 at 10:41
  • 1
    ^ above is better but can `WHERE concat(USER,ID) = "100A"` but this does not use indexes – splash58 Jan 30 '18 at 10:42

1 Answers1

0

first you need to split string like this 100 and A Check Output. and then you can execute query. here is the example

<?php
  $string='100A';
  $parts = preg_split("/(,?\s+)|((?<=[a-z])(?=\d))|((?<=\d)(?=[a-z]))/i", $string);
  print_r($parts );
  //so you can execute query
  SELECET * FROM table1 WHERE USER = $parts[0]  and ID = $parts[1] ORDER BY USER
?>

Reference to split string with details

Bilal Ahmed
  • 4,005
  • 3
  • 22
  • 42