title: convert string in mysql DB to an array
body: <p>the code shown below performs an mysql query using implode() to search for multiple variables in one expression, which i like:</p>
  
  <pre><code>&lt;?
  include("connect.php"); // file to connect to db
  
  $states = array('CA','CO','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 have run into a new issue. as you can see from the above 'states' is hard-coded.</p>
  
  <p>i want the user to be able to select the states they want to pull, have that choice saved to a separate table in the DB, and then have that list read into the 'states' array shown above. Something like this:</p>
  
  <pre><code>&lt;?
  include("connect.php"); // file to connect to db
  
  $sql_gs="SELECT states_c FROM states WHERE id='1'";
  $result_gs=mysql_query($sql_gs);
  $row_gs = mysql_fetch_row($result_gs);
  $gcs = $row_gs[0];
  
  $states = array($gcs);
  $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 this code throws an error.</p>
  
  <p>what is saved to the states table noted above, and what is contained in the states_c field, a VARCHAR field, is this:</p>
  
  <pre><code>'CA','CO,'TX'
  </code></pre>
  
  <p>so the '$gcs' variable in the code above ...</p>
  
  <pre><code>echo $gcs; // result 'CA','CO,'TX'
  </code></pre>
  
  <p>in other words, the <em>text</em> of $gca (for 'get chosen states') is <em>exactly</em> the same as the text in the hard-coded version above that works</p>
  
  <p>but when i try to place the results of the $gca variable, the exact same text, i get an error, no data is pulled, because in this statement</p>
  
  <pre><code>    $states = array($gcs); // $gcs reads exactly as 'CA','CO,'TX'
  </code></pre>
  
  <p>the data is not read, whereas in this one</p>
  
  <pre><code>    $states = array('CA','CO,'TX');
  </code></pre>
  
  <p>the states are recognized and the code fires.</p>
  
  <p>what is the issue with trying to place the same text in this line of code via a named variable as opposed to 'spelling it out' in a hard coded fashion?</p>
  
  <p>TIA</p>
  
  <p>===================</p>
  
  <p>UPDATE</p>
  
  <p>I tried this:</p>
  
  <pre><code>&lt;?
  include("connect.php"); // file to connect to db
  
  $sql_gs="SELECT states_c FROM states WHERE id='1'";
  $result_gs=mysql_query($sql_gs);
  $row_gs = mysql_fetch_row($result_gs);
  $gcs = $row_gs[0];
  
  $states = explode("','", $gcs); // replaces $states = array('CA','CO','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['mail_state']; 
  }
  
  ?&gt;
  </code></pre>
  
  <p>but still no result ...</p>