T
T
Theory Theory2021-06-07 12:52:04
PHP
Theory Theory, 2021-06-07 12:52:04

How to compare strings?

The database contains the strings "6x6", "4x4", "8x4", etc.

But some "x's" are in English, and some are in Russian.
I'm writing a filter, and I need to compare the values ​​from the form with the value from the database.
In the form, all "x" " in English, but they return false with Russian "x" for comparisons

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Neverov, 2021-06-07
@Narbek

Read about the normal forms of databases and it will be much easier for you to work.
It is enough to observe the first 3.
"6x6" should not be in the database. It should be 2 different columns for "6" and "6".
In your case, make a crutch. If you only want an exact match, then just use two OR queries :WHERE `value`='6x6' OR `value`='6х6'

N
N, 2021-06-07
@Fernus

<?php

// Если прям банально...то так тупо можно:


// ВАРИАНТ 1
$str = str_replace('х', 'x', '6x6'); // В первом случае "х" - русская, во втором - английская
// И в запросе:
$sql =  "SELECT * FROM `table` WHERE REPLACE(`field`, 'х', 'x') = '".$str."'"; // В первом случае "х" - русская, во втором - английская

// ВАРИАНТ 2
//В запросе:
$sql =  "SELECT * FROM `table` WHERE REPLACE(`field`, 'х', 'x') = REPLACE('6x6', 'х', 'x')"; // В первом случае "х" - русская, во втором - английская

// P.S.: Не указано какая БД...я отталкивался от MySQL, если что...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question