Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

php - count number of property available for member according to there zip code

i have two table

1) member

  • member_id
  • name
  • address
  • zip

2) property

  • property_id
  • property_name
  • property_zip

i want to list all the member zip (without duplicate) and show the count of property for each zip code in a table


Member Zip | Property Count

95674 | 50

95852 | 90

95614 | 0

95070 | 5

its have multiple member with same zip code and also multiple property with same zip code

i don't want any repeat on the Member Zip output column.

i have 5 member with 92550 & 10 member with 82475, i have to show

92550
82475

& on property table i have 10 with zipcode 82475 and 4 with zip code 92550.

Final O/P

92550 (4)
82475 (10)

can anyone help me to find it ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this

SELECT a.zip, COUNT(b.propety_zip)
FROM member a
LEFT JOIN propety b
ON a.zip = b.propety_zip
GROUP BY a.zip

Edit

I used your code

$checke = "SELECT a.zip, COUNT(b.property_zip) AS property_count FROM member a LEFT JOIN property b ON a.zip = b.property_zip GROUP BY a.zip";
$rsd = mysql_query($checke) or die(mysql_error()); ?> 

<table width="600" style="font-size:12px; border:1px solid #000000; text-align:center;" cellpadding="0" cellpadding="0">
  <tr> 
    <td><strong>Zip</strong></td> 
  </tr>
  <?php while($row = mysql_fetch_array($rsd)) { ?> 
  <tr> 
    <td><h2><?php echo $row['zip'] . " (" . $row['property_count'] .")"; ?></h2></td> 
 </tr> 
 <?php }  ?> 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...