Jump to content


making site stats, but need help with a join

  • Please log in to reply
2 replies to this topic

#1 tjhilder

  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 14 December 2005 - 04:10 AM


I'm creating a site stats script, I have completed one but theres so much code involved, so I was wondering if someone could help me put it into some smaller code.

basicly I have four queries with code like this:
$member_count = "SELECT count(member_id) AS member_c FROM members";
if ($one = mysql_query ($member_count)) { // Run the query.
    $row = mysql_fetch_array ($one); // Retrieve the information.
    echo "<tr><td class=\"left\">Members:</td><td class=\"right\">{$row['member_c']}</td></tr>";
} else { // Couldn't get the information.
    print "<p>Couldn't retrieve the entry because: <b>" . mysql_error() . "</b>. The query was $member_count.</div></div>";

so imagine that, but times four, how would I go about putting all of them into one query? or is it not possible?

thanks in advance.

#2 ryanlwh

  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 14 December 2005 - 05:33 AM

what are the other queries?
Please use EDIT * 100...
Please use
or [php] * 1000...


#3 tjhilder

  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationKent, UK

Posted 14 December 2005 - 05:49 AM

thanks for the reply, I just gone searching and found my answer in [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=79329&hl=\" target=\"_blank\"]this topic[/a].

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] ([span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(*) FROM table) AS affs, ([span style=\'color:blue;font-weight:bold\']SELECT[/span] SUM(downloads) FROM downloads) AS dnum [!--sql2--][/div][!--sql3--]

thanks for your interest tho :) now my query looks like this

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--]$stats_count = "[span style=\'color:blue;font-weight:bold\']SELECT[/span]
([span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(member_id) FROM members) AS member_c,
([span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(news_id) FROM news) AS news_c,
([span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(comment_id) FROM comments) AS comment_c,
([span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(message_id) FROM messages) AS message_c
"; [!--sql2--][/div][!--sql3--]

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users