Jump to content

Recommended Posts

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";			


 

Link to comment
https://forums.phpfreaks.com/topic/152444-using-a-subquery-to-count/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.