Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-28
6
Medium Priority
?
220 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Technology Partners: 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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

609 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