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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.