I'm trying to find a way to compare some letters of my text input with a column on a MYSQL table. Here's my code:
$query = mysqli_query($conn, "SELECT nicename, phonecode FROM country.country WHERE phonecode=$ccode");
What I want is to compare the first two or three letters from my variable $ccode
to the phonecode
from table country
.
I tried using $ccode%
like I would do for normal text but it didn't work.
The Database field phonecode contains international phone codes and variable $ccode contains the full number of a person. I have to extract the country code from the variable $ccode and compare it with the database field.
I don't know PHP more but as per C# we need to add dynamically parameter value.
$tempQuery = "SELECT nicename, phonecode FROM country.country WHERE phonecode like ";
SubString of your $ccode and then add into query
$query = mysqli_query($conn, $tempQuery + "'%" + $ccode + "%'");
Use SUBSTR
$ccode=substr($ccode,0,2); //for two digit, if you want 3 digit replace 2 with 3.
mysqli_query($conn, "SELECT nicename, phonecode FROM country.country
WHERE phonecode=$ccode");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.