Solved

How can i output the SQL count(*) on WebPage ???

Posted on 2004-08-28
6
209 Views
Last Modified: 2013-12-12
Hi

If i have a simple SQL as follow:

Member and Post Tables

select distinct(member.memb_id), count(post.memb_id) FROM member, post where member.memb_id = post.memb_id AND member.surname = 'some input from search query' GROUP BY post.memb_id;

If i run this script in mysql it shows the result fine with each Member ID and The Toal Post Message.
However when i try to implement into PHP it cant show the Total Post Message.

So my question is how to make it display into HTML ?

This is the output from mysql screen
+---------+----------------------+
| memb_id | count(post.memb_id) |
+---------+----------------------+
|       1 |                   14 |
|      35 |                    9 |
|     191 |                   23 |
|     204 |                    3 |
|     208 |                   18 |
|     222 |                    2 |
|     296 |                    7 |
|     322 |                   25 |
|     330 |                   17 |
|     354 |                    6 |
|     369 |                   18 |
|     462 |                   12 |
|     474 |                   15 |
|     490 |                    8 |
|     496 |                   15 |
|     601 |                   16 |
|     627 |                    5 |
+---------+----------------------+

Sorry for my bad english :P
Thanks for helps and suggestions
0
Comment
Question by:chockmilk
  • 2
  • 2
  • 2
6 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11920498
<?php

// Your DB connection ...

$query = "select distinct(member.memb_id) as MemberId , count(post.memb_id) As CountPost FROM member, post where member.memb_id = post.memb_id AND member.surname = 'some input from search query' GROUP BY post.memb_id";

$result = mysql_query($query) or die("Select Query Error : " . mysql_error());

?>

<table border='1' cellspacing = '0' cellpadding='1'>
<tr>
<td> memb_id </td>
<td> post.memb_id </td>
</tr>

<?php

while($row = mysql_fetch_array($result))
{

  $MemberId = $result['MemberId'];
  $CountPost = $result['CountPost'];

  echo "<tr> <td> $MemberId </td> <td> $CountPost </td> </tr>";
}

?>

</table>
0
 
LVL 10

Expert Comment

by:frugle
ID: 11920591
<?php

// Your DB connection ...

$query = "select distinct(member.memb_id) as MemberId , count(post.memb_id) As CountPost FROM member, post where member.memb_id = post.memb_id AND member.surname = 'some input from search query' GROUP BY post.memb_id";

$result = mysql_query($query) or die("Select Query Error : " . mysql_error());

?>

<table border='1' cellspacing = '0' cellpadding='1'>
<tr>
<td> memb_id </td>
<td> post.memb_id </td>
</tr>

<?php

$TotalPost = 0;

while($row = mysql_fetch_array($result))
{

  $MemberId = $result['MemberId'];
  $CountPost = $result['CountPost'];

  $TotalPost = $TotalPost + $result['CountPost'];

  echo "<tr> <td> $MemberId </td> <td> $CountPost </td> </tr>";
}

  echo "<tr> <td> TOTAL POSTS:</td> <td> $TotalPost </td> </tr>";

?>

</table>

Hope this answers the question.

Mike
0
 

Author Comment

by:chockmilk
ID: 11920606
hi i think u got my question wrong..
Probably of my poor explaination :(

I could perform the HTML output but it only show the disntinct memb_id
but not for the count(post.memb_id).

I use :

<table border='1' cellspacing = '0' cellpadding='1'>
<tr>
<td> memb_id </td>
<td> count(post.memb_id) </td>
</tr>

$countRow = mysql_num_rows($result);

for($i=0; $i<$countRow; $i++)
{
    $row = mysql_fetch_array($result);
    echo "<tr> <td> $row["memb_id"] </td> <td> $row["HERE DONT KOW TO DISPLAY the count(post.memb_id)"] </td> </tr>";
}

i hope U got what i mean.
Anyway thx for the suggestion.... :D


0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Accepted Solution

by:
frugle earned 125 total points
ID: 11920629
try altering your SQL code:

SELECT count(post.memb_id) AS mempostcount

then print:

$row["mempostcount"]

http://dev.mysql.com/doc/mysql/en/SELECT.html

Mike
0
 

Author Comment

by:chockmilk
ID: 11920706
Man Frugle u are my man :)
this code work perfectly

SELECT count(post.memb_id) AS mempostcount

then print:

$row["mempostcount"]


I am so happy......

Thank alot man...

Cheeeeer
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 11920721
:-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question