title: Convert sql to mysqli_prepare with variable variables
body: <p>I'm having trouble to convert my code from sql to mysqli. $XX can be 1 or 0. When $XX=1 I want to search for it. When $XX=0, there must be no search for $XX. Same for $YY.</p>
  
  <p>Old code</p>
  
  <pre><code>$sql = "SELECT name FROM tabel WHERE 1=1";    
  if (!empty($XX)) {$sql .= " AND XX = 1 ";}    
  if (!empty($YY)) {$sql .= " AND YY = 1 ";}    
  </code></pre>
  
  <p>When $XX=1 and $YY=1, the code will look like:</p>
  
  <pre><code>$sql = "SELECT name FROM tabel WHERE 1=1 AND XX = 1 AND YY = 1";
  </code></pre>
  
  <p>When $XX=0 and $YY=1, the code will look like:</p>
  
  <pre><code>$sql = "SELECT name FROM tabel WHERE 1=1 AND YY = 1";
  </code></pre>
  
  <p>When $XX=0 and $YY=0, the code will look like:</p>
  
  <pre><code>$sql = "SELECT name FROM tabel WHERE 1=1";
  </code></pre>
  
  <p>The 'problem' is that I do not want to search for XX=0 because that excludes all XX=1 answers. When XX=0, it should not search for XX.</p>
  
  <p>New code</p>
  
  <pre><code>$stmt = mysqli_prepare($link, "SELECT name FROM tabel WHERE XX=? and YY=?");    
  mysqli_stmt_bind_param($stmt, "ii", $XX, $YY);          
  </code></pre>
  
  <p>Who knows how the mysqli code must look like? Thanks!</p>