eerikk2 Posted February 24, 2010 Share Posted February 24, 2010 I have my sql database call test and this database is used to hold user uploaded data via php form. This database has rows by the name of SpeciesName and phyla. I want to make a list of all the SpeciesName's, but i want them to be listed under their phyla. So say we have light-bulb tunicate. i want it to be listed under the chordata phyla along with all the other SpeciesNames where the row phyla = chordata. then if someone was to upload info on a star fish with the phyla arthropod then another list would come up showing starfish under arthropod. I know how to display all the SpeciesName's under their phyla but if there is a double there will be two of the same phyla's. If there was two chordata entries then the results would be Chordata light-bulb tunicat Chordata SpeciesName i want the two, light-bulb tunicate and the other Chordata's to be under one. here is my current code if it helps <html> <body> <ul> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT phyla, SpeciesName FROM Species ORDER BY phyla"); while($row = mysql_fetch_array($result)){ echo "<li><a>" .$row ['phyla']. "</a>"; echo "<li><a>" .$row ['SpeciesName']. "</a></li>"; } mysql_close($con); ?> </ul> </body> </html> Link to comment https://forums.phpfreaks.com/topic/193178-results-from-row/ Share on other sites More sharing options...
developerdave Posted February 24, 2010 Share Posted February 24, 2010 Try using this SQL SELECT `phyla`, `SpeciesName` FROM Species GROUP BY phyla Link to comment https://forums.phpfreaks.com/topic/193178-results-from-row/#findComment-1017386 Share on other sites More sharing options...
eerikk2 Posted February 25, 2010 Author Share Posted February 25, 2010 GROUP BY only displays the phyla's What if i were to have a drop down menu on the page for uploads that have a choice of different phylas? and then i would only display the phyla in the list if a row contains the phyla? but i'm not sure how to do the latter. could you help me Link to comment https://forums.phpfreaks.com/topic/193178-results-from-row/#findComment-1017821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.