tjhilder Posted December 14, 2005 Share Posted December 14, 2005 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 https://forums.phpfreaks.com/topic/3043-making-site-stats-but-need-help-with-a-join/ Share on other sites More sharing options...
ryanlwh Posted December 14, 2005 Share Posted December 14, 2005 what are the other queries? Link to comment https://forums.phpfreaks.com/topic/3043-making-site-stats-but-need-help-with-a-join/#findComment-10187 Share on other sites More sharing options...
tjhilder Posted December 14, 2005 Author Share Posted December 14, 2005 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 https://forums.phpfreaks.com/topic/3043-making-site-stats-but-need-help-with-a-join/#findComment-10188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.