Hello, I was wondering if anyone could help me with some php code to pull stats from a mysql db. I wanted to show how many forums are hosted on my index page from this sql. $sql[] = " CREATE TABLE " . $accessname . "_forums ( forum_id smallint(5) UNSIGNED NOT NULL, cat_id mediumint(8) UNSIGNED NOT NULL, forum_name varchar(150), forum_desc text, forum_status tinyint(4) DEFAULT '0' NOT NULL, forum_order mediumint(8) UNSIGNED DEFAULT '1' NOT NULL, forum_posts mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_topics mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, forum_last_post_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, prune_next int(11), prune_enable tinyint(1) DEFAULT '0' NOT NULL, auth_view tinyint(2) DEFAULT '0' NOT NULL, auth_read tinyint(2) DEFAULT '0' NOT NULL, auth_post tinyint(2) DEFAULT '0' NOT NULL, auth_reply tinyint(2) DEFAULT '0' NOT NULL, auth_edit tinyint(2) DEFAULT '0' NOT NULL, auth_delete tinyint(2) DEFAULT '0' NOT NULL, auth_sticky tinyint(2) DEFAULT '0' NOT NULL, auth_announce tinyint(2) DEFAULT '0' NOT NULL, auth_vote tinyint(2) DEFAULT '0' NOT NULL, auth_pollcreate tinyint(2) DEFAULT '0' NOT NULL, auth_attachments tinyint(2) DEFAULT '0' NOT NULL, PRIMARY KEY (forum_id), KEY forums_order (forum_order), KEY cat_id (cat_id), KEY forum_last_post_id (forum_last_post_id) );"; Code (markup): Thanks for your time to look at this. Regards, Jay
You just want to show how many Forums there are? If so, forum_id is the Primary Key so a straight 'count' will show how many rows there are in the table (and therefore how many Forums). e.g. SELECT COUNT(*) as NumForums from tablename If you were only interested in Forums with a certain status then you would have to qualify the Query: e.g. SELECT COUNT(*) as NumForums from tablename WHERE forum_status = '1' (or whatever value you're intersted in). Is that the kind of thing you're after?
Yes, thanks you. Another member has helped me out on this. Thanks again for your response. Regards, Jay