Copy distinct results to new table

From: Date: Wed, 20 Mar 2002 13:02:56 +0000
Subject: Copy distinct results to new table
Groups: php.db 
Request: Send a blank email to php-db+get-17779@lists.php.net to get a copy of this message
Hi there everyone, How can I copy distinct results of a query to a table in a DB? I have 3 pulldowns, the first one selects the category, then the second one gets the holiday type based on the category, and the third one gets from countries where category = category AND holiday type = holiday type. The problem is there is almost 30,000 entries which it needs to sort through and it takes a few seconds for each pulldown to be calculated, is there a better way than the below Basically i'm guessing I can grab the results and then insert them into a seperate table so that I only save the unique results and so don't have to sort once i've created the new table? Thanks for your help everyone, Chris (For the first pulldown): <form method="post" action="#form1"> <form method="post" action="#form1"> <div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"> <?$result = mysql_query("select distinct category from search ORDER BY category");?> <select name="category" onChange="submit()"> <? if ($category ==""){ ?> <option>Make a Selection</option> <?} else { ?> <option>Selected >>></option> <? }?> <? if ($result) { while ($myrow = mysql_fetch_array($result)) { echo "<OPTION VALUE=\"".$myrow["category"]."\">". $myrow["category"]." </OPTION>"; }?> </select> <? } ?> </font></b></div> </form> For the second pulldown: <form method="post" action="#form2"> <div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"> <?$result = mysql_query("select distinct type from search WHERE category = '$category' ORDER BY type ");?> <select name="type" onChange="submit()"> <? if ($type ==""){ ?> <option>Make a Selection</option> <?} else { ?> <option><<< Selected >>></option> <? }?> <? if ($result) { while ($myrow = mysql_fetch_array($result)) { echo "<OPTION VALUE=\"".$myrow["type"]."\">". $myrow["type"]." </OPTION> "; }?> </select> <? } ?> <input type="hidden" name="category" value="<?=$category?>"> </font></b></div> </form> For the third pulldown: <form method="post" action="#search"> <div align="center"><b><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"> <?$result = mysql_query("select distinct country from search WHERE category = '$category' AND type = '$type' ORDER BY country");?> <select name="country" onChange="submit()"> <? if ($country ==""){ ?> <option>Make a Selection</option> <?} else { ?> <option><<< Selected >>></option> <? }?> <? if ($result) { while ($myrow = mysql_fetch_array($result)) { echo "<OPTION VALUE=\"".$myrow["country"]."\">". $myrow["country"]." </OPTION> "; }?> </select> <? } ?> <input type="hidden" name="type" value="<?=$type?>"> <input type="hidden" name="category" value="<?=$category?>"> </font></b></div> </form>

« previous php.db (#17779) next »