-1

So I have a table named pins that has 3 columns that need to be taken into consideration. These columns are plan and order_id.

I need to get a count for all of the pins that have an order_id=0 and plan=9.

This is what I have so far:

$qT="SELECT plan, COUNT(*) as cnt FROM pins WHERE order_id=0 and plan=9";
$res=mysql_query($qT);<br/>
mysql_free_result($res);

while($row = mysql_fetch_array($res)) {<br/>
echo $row['plan'];<br/>
}

Any help in displaying the results would be a great help.

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Michael S
  • 141
  • 9

1 Answers1

1

Try to group your pin using GROUP BY, So

$result = mysql_query("SELECT plan, COUNT(pin) as cnt FROM pins WHERE (order_id=0 and plan=9) GROUP BY plan");

echo "<table border='1' style='border-collapse: collapse'>";  
echo "<th>Plan</th><th>Count</th>";  
while ($row = mysql_fetch_array($result))   
{  
   echo "<tr><td>".$row['plan']."</td><td>".$row['cnt']."</td></tr>";
}

echo "</table>";        
mysql_free_result($result);
?>
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103