Solved

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

Posted on 2004-08-28
6
207 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

912 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now