Jump to content

making site stats, but need help with a join


tjhilder

Recommended Posts

Hi,

 

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.

Link to comment
Share on other sites

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--]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.