title: Allowing Optional Parameters for MySQL Query
body: <p>I have a search page that has multiple fields that are used to create a refined search. Every field is optional. I'm trying to start crafting my sql query so that it will work given the proper variables but I'm having trouble.</p>
  
  <p>Here is the SQL query I currently have:</p>
  
  <pre><code>SELECT
    indicator.indid,
    indicator.indicator,
    indtype.indtype,
    provider.provider,
    report.report,
    actor.actor
  FROM
    actor,
    indicator,
    indtype,
    report,
    provider
  WHERE
    indicator.indtypeid = indtype.indtypeid
    AND indicator.actorid = actor.actorid
    AND indicator.reportid = report.reportid
    AND report.providerid = provider.providerid
    AND indicator.indicator LIKE '%$indicator%'
    AND indicator.indtypeid = $indtypeid;
  </code></pre>
  
  <p>Whenever I provide an <code>indicator</code> and an <code>indtypeid</code>, the search works just fine. However, when I leave the <code>indtypeid</code> field blank, and have the variable set to <code>*</code> (as its default value), the query returns no results. I've tried playing with the query manually and it doesn't seem to like the <code>*</code> or a <code>%</code> sign. Basically, if only an indicator is specified and no <code>indtypeid</code> is specified, I want to return all indicators for all <code>indtypeids</code>. </p>
  
  <p>I'm sure I'm missing something minor, but I would appreciate any assistance that could be provided. I may be going about this all wrong in the first place.</p>