Home > Blockchain >  Can't fetch data from MySQL with almost same name in PHP
Can't fetch data from MySQL with almost same name in PHP

Time:12-26

I have inserted 3 rows to my DB table orders.

One of the columns that I fetch data from is barname_num.

The 3 rows have these values for the mentioned col :

hdm1350WIRG6351-01

hdm1350WIRG6351-02

hdm1350WIRG6351-03

The problem is that none of these are fetched ! I'm using mysqli_fetch_array and I tried mysqli_fetch_assoc but still not working.

All other rows are fine and the problem is only with these 3 rows ! What is the problem ?!

Update* : I tried to change Collation but it is not relevant.

Here is the php code by the way :

$sql = "SELECT * FROM orders WHERE barname_num = ?";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt , $sql)){
    echo "sql not prepared!";
    exit();
}
else{
    mysqli_stmt_bind_param($stmt , "s" , $barname_num);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    if($r = mysqli_fetch_array($result)){
.
.
.

CodePudding user response:

It seems like there may be some invisible characters in the data. As a workaround until you can straighten that out, you can use LIKE to ignore them.

$sql = "SELECT * FROM orders WHERE barname_num LIKE ?";
$stmt = mysqli_stmt_init($conn);
$barname_num = "%$barname_num%";
mysqli_stmt_bind_param($stmt , "s" , $barname_num);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($r = mysqli_fetch_array($result)){

CodePudding user response:

remove white space from value and try or You can use LIKE .

  • Related