timcadieux Posted April 3, 2009 Share Posted April 3, 2009 I'm using the below query to count the number of Names attached to each particular Unit, but when I ran this Query, WAMP almost died and I lost control of my PC for about 5min until I stopped ALL Services. Ideas? mysql_connect($db_host,$MySqlUN,$MySqlPW); @mysql_select_db($database) or die( "Unable to select databases"); // Build SQL Query $query = "SELECT ID, fldUnit, (SELECT COUNT(*) FROM tblnames as NUMS WHERE tblUnit_ID = Units.ID) as myCount from tblunit AS Units"; $result = mysql_query($query) or die($query); // fldunit echo "<tr valign='middle'>\n"; echo "<tr>\n"; echo "<td style='background-color: #fcfaf6;'>Field Unit: "; echo "</td>\n"; echo "<td><select name='lstUnits' id='lstUnits'>\n"; // now you can display the results returned while ($row= mysql_fetch_array($result)) { echo "<option value='".$row[0]."'"; echo ">".$row[1]." ".$NUMS."-Records</option>\n"; } //Close the db connection mysql_close(); $query=''; echo "</select></td>\n"; echo "</tr>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/152444-using-a-subquery-to-count/ Share on other sites More sharing options...
fenway Posted April 3, 2009 Share Posted April 3, 2009 that's a dependent subquery... no surprise. Quote Link to comment https://forums.phpfreaks.com/topic/152444-using-a-subquery-to-count/#findComment-800629 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.