PHP / MSSQL Query with LIKE clause

Im trying to run a MSSQL query within PHP and its working fine - however, if i replace a certain part of the query with a variable i get an error...

basically the code I have thats working: is as follows:

$PartNo1 = "123456";
$PartNo2 = "654321";

$query = "
select * from table
where Path LIKE '123456 -> 654321'
";

$runquery = mssql_query("$query");

echo 'Total records' . mssql_num_rows($runquery);

^ That works fine. now i'm trying to replace the LIKE clause with the variables instead of static text, so i want to replace:

where Path LIKE '123456 -> 654321'

WITH:

where Path LIKE '$PartNo1 -> $PartNo2'

but it fails... it always returns 0 results. - I've tried a few different combinations of variables and static text and it works some ways but not others.

where Path LIKE '123456 -> 654321' --- works!

where Path LIKE '$PartNo1 -> 654321' ----- works!

where Path LIKE '123456 -> $PartNo2' ---- doesnt work

where Path LIKE '$PartNo1 -> $PartNo2' ----- doesnt work

I've echo'd the query as a whole, to see whats its generating and the query thats displayed is exactly what i want (123456 -> 654321) - if i take the code its generated and run it in sql management studio it works perfectly and gives me 4 rows of results.

Just a thought: it is a LIKE search, and in the original question you posted what the queries looked like, only later to add the "%" character... is it possible that the "%" is getting left out by accident on the query that uses the variables?

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.