how to get each element in one record from mysql database <p>I am trying to get each element in one record 'Pests' in database 'crop'.Actually my purpose is to get all the distinct pests in 'Pests' field.</p> <p>BUT There are not only one element in 'Pests' in database. For example:</p> <pre><code>Name Pests </code></pre> <hr> <pre><code>Name1 Grasshopper Thrips Potato Leafhoppe Stink Bugs ... ... Name2 Green Cloverworm Mexican Bean Bettle ... ... </code></pre> <p>My code is like the following. But the result is not what I want. This will display all the pest in each column. But I want all the distinct pests in all column and display each pest in a table, like</p> <pre><code>Pest | Grasshopper|Thrips|Potato Leafhoppe|Stink Bugs|Green Cloverworm|Mexican Bean Bettle|... ... </code></pre> <p>Im so appreciate if anyone could give me some hint for how to achieve this. Thanks so much!</p> <pre><code>$search = "SELECT distinct Pests from crop ORDER BY Pests ASC"; $result = mysql_query($search); echo '&lt;table&gt;'; echo '&lt;tr&gt;'; while ($rs = mysql_fetch_row($result)){ echo '&lt;td&gt;'.$rs[0].'&lt;/td&gt;'; } echo '&lt;/tr&gt;'; echo '&lt;/table&gt;'; </code></pre>