anchor.diff:  	}
   	else
   	{
  -		sql1 = "SELECT pid, total FROM products_total WHERE pid IN (SELECT * FROM products WHERE cid = " + category + " ORDER BY total LIMIT 10";
  +		sql1 = "SELECT * FROM products_total WHERE pid IN (SELECT pid FROM products WHERE cid = " + category + ") ORDER BY total LIMIT 10";
   	}
   	
  -	//Users/states and totals
  -	//per product per user/state
  +	//sql2: Users/states and totals for row labels
  +	//sql3: per product per user/state for table data
   	
   	if (scope.equals("states"))
   	{
   		if (category == null || category.equals("all") || category.equals("null"))
   		{
   			if (state != null && !state.equals("all") && !state.equals("null"))
  +			{
   				sql2 = "SELECT * FROM states_total ORDER BY total LIMIT 20";
  +				sql3 = "SELECT * FROM states_products_total AS spt WHERE spt.pid IN (SELECT pt.pid FROM products_total as pt ORDER BY pt.total LIMIT 10)";
  +			}
   			else
  -				sql2 = "SELECT * FROM states_total WHERE state = " + state;
  +			{
  +				sql2 = "SELECT * FROM states_total WHERE state = '" + state + "'";
  +				sql3 = "SELECT * FROM states_products_total AS spt WHERE spt.state = '" + state + "' AND spt.pid IN (SELECT pt.pid FROM products_total AS pt ORDER BY pt.total LIMIT 10)";
  +			}
   		}
   		else
   		{
   			if (state != null && !state.equals("all") && !state.equals("null"))
  -				sql2 = "SELECT * FROM states_categories_total WHERE cid = " + category + " ORDER BY total LIMIT 20";
  +			{
  +				sql2 = "SELECT state, total FROM states_categories_total WHERE cid = " + category + " ORDER BY total LIMIT 20";
  +				sql3 = "SELECT spt.state, spt.total FROM state_products_total AS spt WHERE spt.pid IN (SELECT pt.pid FROM products_total AS pt WHERE pt.pid IN (SELECT p.pid FROM products AS p WHERE p.cid = " + category + ") ORDER BY pt.total LIMIT 10)";
  +			}
   			else
  -				sql2 = "SELECT * FROM states_categories_total WHERE cid = " + category + " AND state = " + state;
  +			{
  +				sql2 = "SELECT * FROM states_categories_total WHERE cid = " + category + " AND state = '" + state + "'";
  +				sql3 = "SELECT spt.state, spt.total FROM state_products_total AS spt WHERE spt.state = '" + state + "' AND spt.pid IN (SELECT pt.pid FROM products_total AS pt WHERE pt.pid IN (SELECT p.pid FROM products AS p WHERE p.cid = " + category + ") ORDER BY pt.total LIMIT 10)";
  +			}
   		}
   	}
   	else
  
positive.code: 	rs1 = stmt1.executeQuery(sql1); //1 = pid, 2 = total
  	rs2 = stmt2.executeQuery(sql2); //1 = uid OR state, 2 = total
  	rs3 = stmt3.executeQuery(sql3);	//1 = uid OR state, 2 = pid, 3 = total
  	
  	/*
  	conn.commit();
  
negative.code: 	String state = request.getParameter("state");
  	String category = request.getParameter("category");
  	
  	//sql1: Products and Totals for column labels
  	
  	if(category == null || category.equals("all") || category.equals("null"))
  	{
  