title: array based query php
body: <p>instead of searching a mysql DB for one variable at a time, i want to search for a number of variables, and fit it into the initial query string</p>
  
  <p>so instead of</p>
  
  <pre><code>$query="SELECT * FROM table1 WHERE state = 'CA' OR state = 'CO' OR state = 'TX'";
  </code></pre>
  
  <p>i want</p>
  
  <pre><code>$states = ("CA,CO,TX");
  $query="SELECT * FROM table1 WHERE state = $states";
  </code></pre>
  
  <p>I have tried</p>
  
  <pre><code>&lt;?
  include("connect.php"); // file to connect to db
  $states = array(CA,TX);
  $states_str = implode(",", $states);
  
  
  $query="SELECT * FROM table1 WHERE state IN ($states_str)";
  
  $result=mysql_query ($query);
  while($row = mysql_fetch_array($result)) {
  echo $row['state'];
  }
  
  ?&gt;
  </code></pre>
  
  <p>but i get this error message</p>
  
  <pre><code> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in  ... on line 11
  </code></pre>
  
  <p>this is line 11</p>
  
  <pre><code>while($row = mysql_fetch_array($result)) {
  </code></pre>
  
  <p>however, if i use this code, i get a result, only to show that when i switch back to the old conventional query it works</p>
  
  <pre><code>&lt;?
  include("connect.php"); // file to connect to db
  $states = array(CA,TX);
  $states_str = implode(",", $states);
  
  
  $query="SELECT * FROM table1 WHERE state = 'CA'";
  
  $result=mysql_query ($query);
  while($row = mysql_fetch_array($result)) {
  echo $row['state'];
  }
  
  ?&gt;
  </code></pre>
  
  <p>but then i am bypassing the implode() thing, which i found somewhere else but it is not working for me</p>