?
Solved

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

Posted on 2004-08-28
6
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
frugle earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

800 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