1

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?

Sam
  • 7,252
  • 16
  • 46
  • 65
Nirjhor
  • 73
  • 2
  • 4
  • 9

1 Answers1

1

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);
Community
  • 1
  • 1
EvilEpidemic
  • 479
  • 8
  • 17
  • My Site ID's are like: US17001, UK17393... and My $row["bs_id_site"] returns like: 17001, 17393... In such case How to compare, can you tell me please? – Nirjhor Jul 10 '13 at 10:50