Tuesday, 15 June 2010

php - Populate HTML table from MYSQL and counting rows -


I am trying to populate an HTML table with mysql data, I have the following data in MySQL: / P>

  id, ip, referral   

I want to create a table that shows a list of references and how often Is:

  ID, IP, referral 1 1.1.1.1 google.com 2 2.2.2.2 google.com 3 3.3.3.3 Test Comm 4 4.4.4.4 Other dot output:  
  google.com 2 test.com 1 another.com 1   

What I tried was:

  & lt; Table class = "table-table-barbed table-primary" & gt; & Lt; Tbody & gt; & Lt ;? Php $ sql = "select traffic from *"; $ Result = mysql_query ($ SQL); ? & Gt; & Lt ;? Php while ($ row = mysql_fetch_array ($ result)) {? & Gt; & Lt; Tr & gt; & Lt; Td square = "tc" & gt; Font face = "aerial, helvetica, non-serif" & gt; & Lt ;? Php if ($ row ['referal'] == '') {echo "blank referrals"; } Else {echo $ row ['referal']; } & Gt; & Lt; / Font & gt; & Lt; / TD & gt; & Lt; Td square = "tc" & gt; & Lt; Center & gt; & Lt; Font face = "aerial, helvetica, non-serif" & gt; & Lt ;? Php $ referal = $ row ['referal']; $ Sql ​​= "Select COUNT (*) traffic from WHERE referal = $ referal"; $ Num_rows = mysql_num_rows ($ result); Repeat "$ num_rows"; ? & Gt; & Lt; / Font & gt; & Lt; / Center & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;? Php}? & Gt; & Lt; / Tbody & gt; & Lt; / Table & gt;   

But it does not mention each person separately, as well as a new table row for each entry, even though the reunion was similar.

Any help is too big to appreciate.

You might be searching for keyword for GROUP BY SQL: < From the Traffic Group, from the / p>

  referral,   

, select COUNT (*), it will give you the exact table without any additional loop for you Want php

No comments:

Post a Comment