Solved

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

Posted on 2004-08-28
6
206 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
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 …

707 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

17 Experts available now in Live!

Get 1:1 Help Now