The above methods didn’t quite work for me, but I ended up with this and it works great. Posting in case this helps someone else in the same situation. You just need to trim the row based on your results, as it will contain the name of your column along with the word "set".
<?php> include ('database.php'); $query = "SHOW COLUMNS FROM Products LIKE 'Genre'"; $stmt = $con->prepare( $query ); $result = $stmt -> execute(); if ($result) { $row = $stmt -> fetch(PDO::FETCH_ASSOC); $genres = implode($row); $genres = substr($genres,10,strlen($genres)-14); //echo $genres; $genres = preg_split("/','/",$genres); //this is to populate my select box options with set values echo "<select name = 'genre'>"; echo "<option>Select...</option>"; foreach ($genres as $key=>$value) { echo "<option name = '$value' value = '$value'>$value</option>"; }; echo "</select>"; } ?>
source share