Reputation: 73
I am trying to compare a PHP String (123) with a portion of MySQL String (Suppose: BB123).
mysql_query("SELECT * FROM `table` WHERE `site_id` LIKE '".$row["bs_id_site"]."'");
I have used this above query.
But it is not returning the result because of Alpha String (Like: "BB") inside site_id
.
What can be a solution in such case, while comparing PHP String with a part of MySQL String?
If I would compare a Part of PHP String I could use % sign, but what will be the case for MySQL String?
Upvotes: 1
Views: 161
Reputation: 469
You can try;
mysql_query("SELECT * FROM `table` WHERE `site_id` LIKE '__".$row["bs_id_site"]."'");
see example - http://sqlfiddle.com/#!2/63bff/3/0
But you really should not be using mysql_* since these are depreciated,
use msqli_* or PDO instead - Why shouldn't I use mysql_* functions in PHP?
if your PHP string is;
$site_id = 'UK17001';
then use;
substr($site_id, 2);
Upvotes: 1