Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Any php code to extract these?

edited May 2007 in Vanilla 1.0 Help
I would like to include some inline stats on another web page and was wondering if there is any php code I can use to present the following:

1. number of vanilla users
2. total number of discussions
3. total number of comments

Comments

  • SQL sentences:

    Nr of discussions: SELECT COUNT( * ) FROM `LUM_Discussion` ;
    Comments: SELECT COUNT( * ) FROM `LUM_Comment` ;
    Users: SELECT COUNT( * ) FROM `LUM_User` ;

    Now, if you want to call this outside of vanilla. what you need to do is connect to the database and run these queries, like this:
    mysql_connect("[host]","[user name]","[password]") or die(mysql_error()); mysql_select_db("[database name]") or die (mysql_error()); $result= mysql_query("SELECT COUNT( * ) FROM `LUM_Discussion` ;") or die (mysql_error()); $row = mysql_fetch_array($result); $nr_of_discussions = $row[0]; $result = mysql_query("SELECT COUNT( * ) FROM `LUM_Comment` ;") or die (mysql_error()); $row = mysql_fetch_array($result); $nr_of_comments = $row[0]; $result = mysql_query("SELECT COUNT( * ) FROM `LUM_User` ;") or die (mysql_error()); $row = mysql_fetch_array($result); $nr_of_users = $row[0]; echo "Discussions: ".$nr_of_discussions." | Comments. ".$nr_of_comments." | Users: ".$nr_of_users;
  • I have embedded the above code in my other webpage and tried it, but I get an unaccessible error. Access denied for user 'cw_me'@'localhost' to database '[cw_myVanillaBBS]' I have already set the host, user name, password and dbname to the correct ones. Do I need to include some include file in my webpage before I can use these?
  • that error msg usually says "using password, yes" in the end if you have sent a password that wasnt correct. check that you havent made some kind of typo. maybe "password without a " or something. And no. you dont need to include anything to get this to work. This example uses the php methods for sql directly. You should rather use the SQLBuilder class in Vanilla, but I must admit to not understanding it fully myself.
  • thanks, turns out my db name was enclosed in square brackets.
  • ah, i guess I should have said to remove them. So now it works?
  • Now I get this error: Table 'cmwong_Popculture.LUM_Discussion' doesn't exist my table name is cmwong_Popculture. I've copied the above code. Do I need an extra " somewhere?
  • the table is LUM_Discussion. Just use the SQL sentence I used above
  • edited May 2007
    To make the code more flexible, you should use the configuration variable for the database prefix which may not always be LUM_ as in this truncated example.
    SELECT COUNT(*) FROM ".$Context->Configuration['DATABASE_TABLE_PREFIX']."Comment WHERE ...
  • right. except you added a lot of where clauses. please remove them as to not confuse the non sql literates
This discussion has been closed.