title: How to use PHP string in mySQL LIKE query?
body: <p>I am trying to find the number of rows that match a specific pattern. In this example, all that START with "123":</p>
  
  <p>This is working:</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM table WHERE the_number LIKE '123%'");
  $count = mysql_num_rows($query);
  </code></pre>
  
  <p>The problem is the LIKE will vary, so I'm trying to define it in the script, then execute the query, but this is NOT working:</p>
  
  <pre><code>$prefix = "123";
  $query = mysql_query("SELECT * FROM table WHERE the_number LIKE $prefix.'%'");
  $count = mysql_num_rows($query);
  </code></pre>
  
  <p>How can I get this query to work properly in the second example?</p>
  
  <p>EDIT: I've also tried it without the period (also not working):</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM table WHERE the_number LIKE $prefix'%'");
  </code></pre>