Display count of unique values in MySQL db table using PHP -
so have table named pins has 3 columns need taken consideration. these columns plan , order_id.
i need count of pins have order_id=0 , plan=9.
this have far:
$qt="select plan, count(*) cnt pins order_id=0 , plan=9"; $res=mysql_query($qt);<br/> mysql_free_result($res); while($row = mysql_fetch_array($res)) {<br/> echo $row['plan'];<br/> }
any in displaying results great help.
try group pin using group by
,
$result = mysql_query("select plan, count(pin) cnt pins (order_id=0 , plan=9) group 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); ?>
Comments
Post a Comment