crazy/man Posted November 12, 2009 Share Posted November 12, 2009 Hi all. I have two forums reading same database. Forum 1 works under prefix "f1_" Forum 2 works under prefix "f2_" Everything works normaln and both forums read same users but topics and posts are separated. Now i want to, if it is somehow possible, in my post counter.. cout both prefixes if you know what i mean. I want my counter read data from 2 tables and provide me a post count. I am using this code right now and every forum has its own post count, but i want to make same post count for both forums. $dt=mysql_fetch_array(safe_query("SELECT count(postID) FROM ".f1_."forum_posts")) ; $posts=$dt[0]; So i want to make something like this: $dt=mysql_fetch_array(safe_query("SELECT count(postID) FROM ".webs2_."forum_posts" + SELECT count(postID) FROM ".f2_."forum_posts")) ; $posts=$dt[0]; I hope you could understand my problem, sorry for my not so good English, i can hardly express myself. Quote Link to comment https://forums.phpfreaks.com/topic/181204-post-counts/ Share on other sites More sharing options...
mikesta707 Posted November 12, 2009 Share Posted November 12, 2009 you could do something like $query = "SELECT count(postID) as one from ...., count(postID) as two from...., one+two as total from..."; Quote Link to comment https://forums.phpfreaks.com/topic/181204-post-counts/#findComment-955971 Share on other sites More sharing options...
monkeytooth Posted November 12, 2009 Share Posted November 12, 2009 Something like: $count1_query = "SELECT COUNT(*) AS count1_rows FROM table_name"; $count1_result = mysql_query($count1_query) or die('View Count SQL Error, query failed<br>' . mysql_error()); $count1_row = mysql_fetch_array($count1_result, MYSQL_ASSOC); $count1 = $count1_row['count1_rows']; $count2_query = "SELECT COUNT(*) AS count2_rows FROM table_name"; $count2_result = mysql_query($count2_query) or die('View Count SQL Error, query failed<br>' . mysql_error()); $count2_row = mysql_fetch_array($count2_result, MYSQL_ASSOC); $count2 = $count2_row['count2_rows']; $totalcounted = $count1+$count2; echo $totalcounted; im sure there is an easier way but this should in theory do the trick once edited to your needs Quote Link to comment https://forums.phpfreaks.com/topic/181204-post-counts/#findComment-955973 Share on other sites More sharing options...
crazy/man Posted November 12, 2009 Author Share Posted November 12, 2009 it works now.. but now how to figure out users posts.. user posts read from two prefixes, same database. Quote Link to comment https://forums.phpfreaks.com/topic/181204-post-counts/#findComment-956510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.