thunderdogg Posted September 2, 2007 Share Posted September 2, 2007 Guys i've set up a very simple SQL database called college. There are some variables within, one of those variables is also called college which is the var that stores the name of the college attended. I have a PHP file which allows me to see the output of all my inputs, what i'd like is at the bottom of that to have a COUNT of all the different universities represented, but i've had no luck with that. My SQL skills are low, i'm trying to teach myself with small projects like this. Please let me know what command i would need to add to the bottom of my output page (which i'll show below) so that I could output the COUNT of different universities. The output page is below at the bottom of it is the current Count Query i've put together, but it's not outputing, thanks!! ---------------- $result = mysql_query("SELECT * FROM college") or die(mysql_error()); echo "<table border='1'> <tr> <th>ID</th> <th>College</th> <th>Major</th> <th>Salary</th> <th>Months</th> <th>College Experience</th> <th>Job Value</th> <th>Overall Education</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['college'] . "</td>"; echo "<td>" . $row['major'] . "</td>"; echo "<td>" . $row['salary'] . "</td>"; echo "<td>" . $row['months'] . "</td>"; echo "<td>" . $row['cexperience'] . "</td>"; echo "<td>" . $row['job'] . "</td>"; echo "<td>" . $row['education'] . "</td>"; echo "</tr>"; } echo "</table>"; $count_query = mysql_query('SELECT COUNT (college) FROM college'); echo $count_query; mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 $count_query = mysql_query('SELECT COUNT(DISTINCT college) FROM college'); echo mysql_result($count_query, 0,0); Quote Link to comment Share on other sites More sharing options...
thunderdogg Posted September 3, 2007 Author Share Posted September 3, 2007 so simple. gracias. works perfectly! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.