dare87 Posted December 3, 2008 Share Posted December 3, 2008 I know there's a way to do this but don't know how... I want to be able to pull all the data out in groups. example ART - FIRST LAST FIRST LAST BAND - FIRST LAST FIRST LAST FIRST LAST This is what I have right now. "tgroup" is the name of the groups. <?php // Connect to the database. require_once ('mysql_connect.php'); // Make the query. $query = "SELECT user_id, first_name, last_name FROM users WHERE webaccess='2' ORDER BY tgroup, last_name ASC"; // Run the query. $result = @mysql_query ($query); // If the query ran w/o error, print out the results. if ($result) { // Table header. echo '<h3><span style="color: #af410d;">Current Faculty</span></h3> <table>'; // Fetch and print all the records. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo ' <tr> <td width="20px"></td> <td>- <a href="teacherpages.php?id=' . $row['user_id'] . '">' . $row['first_name'] . ' ' . $row['last_name'] . '</a><br></td> </tr>'; } // Close the table. echo '</table>'; // Free up the resources. mysql_free_result ($result); } else { // If the query did not run successfully, print out an error message. echo 'No Teachers in the system'; } // Close the database connection. mysql_close(); ?> Thanks for the help Link to comment https://forums.phpfreaks.com/topic/135295-solved-grouping/ Share on other sites More sharing options...
sasa Posted December 3, 2008 Share Posted December 3, 2008 try <?php // Connect to the database. require_once ('mysql_connect.php'); // Make the query. $query = "SELECT user_id, first_name, last_name, tgroup FROM users WHERE webaccess='2' ORDER BY tgroup, last_name ASC"; // Run the query. $result = @mysql_query ($query); // If the query ran w/o error, print out the results. if ($result) { // Table header. echo '<h3><span style="color: #af410d;">Current Faculty</span></h3> <table>'; $last_group = ''; // Fetch and print all the records. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($row['tgroupd'] != $last_group){ echo ' <tr> <td width="20px"></td> <td>'.$row['tgroup'] . ' -</td> </tr>'; $last_group = $row['tgroup']; } echo ' <tr> <td width="20px"></td> <td>- <a href="teacherpages.php?id=' . $row['user_id'] . '">' . $row['first_name'] . ' ' . $row['last_name'] . '</a><br></td> </tr>'; } // Close the table. echo '</table>'; // Free up the resources. mysql_free_result ($result); } else { // If the query did not run successfully, print out an error message. echo 'No Teachers in the system'; } // Close the database connection. mysql_close(); ?> ?> Link to comment https://forums.phpfreaks.com/topic/135295-solved-grouping/#findComment-704809 Share on other sites More sharing options...
dare87 Posted December 3, 2008 Author Share Posted December 3, 2008 That worked great. Thanks sasa Link to comment https://forums.phpfreaks.com/topic/135295-solved-grouping/#findComment-705090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.