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?

1
  • do u want just like this where site_id like '123' Commented Jul 10, 2013 at 10:15

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.