0

I have a table value as below string:

PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92

I get value as random/shuffle order as below to verify if they are exactly matched to the table value:

PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92

or 

PhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8E

or

PhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8F

or

PhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8E

or


PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60

Tried:

select *from table1 where preview like '%PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92PhysicalAddress:E8-6A-64-DE-48-60%' limit 1;

But it is not correct SQL, the input value is random, shuffled where the database value is fixed, i need to match random,shuffled input matching with fixed database value. How to make it very stable?

2
  • so what is your expected result Commented Aug 23, 2019 at 4:00
  • 1
    " i need to match random,shuffled input matching with fixed database value" It's not clear what your asking here Commented Aug 23, 2019 at 4:02

1 Answer 1

1

One way to do this is to split the incoming string into the separate addresses and then check that they all match the table value:

$string = 'PhysicalAddress:E8-6A-64-DE-48-60PhysicalAddress:04-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-8FPhysicalAddress:06-EA-56-08-E6-8EPhysicalAddress:04-EA-56-08-E6-92';
$components = str_split($string, 33);
$query = "SELECT * 
FROM table1 
WHERE preview LIKE '%" . implode("%'\n  AND preview LIKE '%", $components) . "%'";
echo $query;

Output:

SELECT * 
FROM table1 
WHERE preview LIKE '%PhysicalAddress:E8-6A-64-DE-48-60%' 
  AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8E%'
  AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-8F%'
  AND preview LIKE '%PhysicalAddress:06-EA-56-08-E6-8E%'
  AND preview LIKE '%PhysicalAddress:04-EA-56-08-E6-92%'

Demo on 3v4l.org

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it works. I have updated and tested here is my version: 3v4l.org/bC3Lf
Just make sure you sanitize the input to prevent SQL injection attacks, unless you are 100% sure the input is safe.
@YumYumYum is there a problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.