View Full Version : Can anyone tell me...
how I can post the total number of threads in a certain forum on a non-vb page??
Here is a start. I have no idea how to do the query. Can anyone help??
<?php
// Set this to the Forum ID to display
$forum = 20;
require("forum/admin/config.php3");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$forumtitle=htmlspecialchars($forum[title]);
$numberthreads=$forum[threadcount];
<A HREF="forumdisplay.php3?forumid=$forum">$forumtitle</A> has $numberthreads Threads.
?>
90 Views and no one wants to help...
It's not that we don't WANT to help, many of us don't know HOW to help.
Originally posted by Zothip
how I can post the total number of threads in a certain forum on a non-vb page??
read further down in this thread for the answer
http://www.vbulletin.com/forum/showthread.php?threadid=2658
here's what the thread had further down
<?php
require("/full/path/to/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query = "select * from thread";
$resultlatest = mysql_query($query,$db);
$num = mysql_num_rows($resultlatest);
echo "<FONT FACE=\"Verdana, Arial, Helvetica, sans-serif\" SIZE=\"2\">There are currently <b>$num</b> threads on the forums.</font>";
?>
sorry didn't read your question properly... but i think you could work with this code for a per forum version - i don't know php so wouldn't have a clue :(
$query = "select * from thread";
This must be very resource intensive though.... you are reading all of your threads simply to find out how many there are. I think you would be better off with something like this:
SELECT COUNT(*) FROM thread
HTH.
-Chris
[Edited by Chris Schreiber on 09-08-2000 at 04:58 PM]
chris i tried SELECT COUNT(*) FROM thread
and it displayed my total thread count = 1 ?
Originally posted by eva2000
and it displayed my total thread count = 1 ?
Well that sure isn't the correct count! :)
I can't check this now, but I will take a look at this later tonight.... this is valid SQL, I even checked here to make sure: http://www.mysql.com/documentation/mysql/commented/manual.php?section=Counting_rows
-Chris
Is this what you want?
http://www.extremeforums.com/include/forumlist_with_count.inc.php
~Chris
Um...
Wouldn't you just have to get the forumid, then just do something simple like.
<?php
$query = "select forumid from thread where forumid='theforumidyouchose'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
print "There are $num_rows results in that forum";
?>
Keep it simple, thats the way to do it I think.
Originally posted by Chris Schreiber
$query = "select * from thread";
This must be very resource intensive though.... you are reading all of your threads simply to find out how many there are. I think you would be better off with something like this:
SELECT COUNT(*) FROM thread
HTH.
-Chris
[Edited by Chris Schreiber on 09-08-2000 at 04:58 PM]
Not 100% sure, but shouldt that be something more like:
$query=mysql_query("SELECT COUNT(threadid) AS totalthreads FROM thread");
Then you could just grab the total threads by doing something like:
$row=mysql_fetch_array($query);
$totalthreads = $row[totalthreads];
echo "$totalthreads total threads";
???
I didnt think of this the first time, because im not very knowledgable on server load / mysql strain.....etc... So i guess i really didnt care :D
~Chris
<?php
require("forum/admin/config.php3");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query=mysql_query("SELECT COUNT(threadid) AS totalthreads FROM thread");
$row=mysql_fetch_array($query);
$totalthreads = $row[totalthreads];
echo "$totalthreads total threads";
?>
That code shows the total number of posts on the board, not in a specific forum.
FORUM LIST W/ TOTAL THREADS ON NON VB PAGE
http://www.extremeforums.com/include/forumlist_with_count.inc.php
Usage:
include("/full/path/to/forumlist_with_count.inc.php");
forumlist_with_count.inc.php
<?php
require("/full/path/to/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query = "SELECT forumid,title,threadcount FROM forum ORDER BY title ASC";
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<FONT SIZE=\"1\" FACE=\"Verdana, Arial, Helvetica, sans-serif\"> °
<A HREF=\"http://www.extremeforums.com/forums/forumdisplay.php?forumid=$latest_array[forumid]\">$latest_array[title]</A> Currently <b>$latest_array[threadcount]</b> threads</FONT><BR>";
}
?>
HTH
~Chris
Oh yeah,
In my one I left out the MySQL connect code. You'll have to connect to the MySQL and choose the database that vBulletin is in.
Its killing me how a person can ask a question and people can take is so far off topic, and get so turned around
:mad:
Originally posted by Zothip
<?php
require("forum/admin/config.php3");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query=mysql_query("SELECT COUNT(threadid) AS totalthreads FROM thread");
$row=mysql_fetch_array($query);
$totalthreads = $row[totalthreads];
echo "$totalthreads total threads";
?>
That code shows the total number of posts on the board, not in a specific forum.
Read this thread a little closer, im not even the one who posted that code
Roger, I stand corrected. You were correcting someone elses code that had nothing to do with what i asked about in the first place :)
Originally posted by Zothip
Roger, I stand corrected. You were correcting someone elses code that had nothing to do with what i asked about in the first place :)
No problem.....so is the code I gave on the last page what you wanted?
~Chris
Originally posted by TechTalk
No problem.....so is the code I gave on the last page what you wanted?
~Chris [/B]
No, it isnt. I am looking to display the total threads in one forum only. (ie. <A HREF="forumdisplay.php3?forumid=$forum">$forumtitle</A> has $numberthreads Threads.)
-Thomas
Which forum? whats the id??? The above code could easily be modified to only show one
Originally posted by TechTalk
Which forum? whats the id??? The above code could easily be modified to only show one
The forum ID i am trying to post the total threads for is: 20
<?php
require("/full/path/to/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
$query = "SELECT forumid,title,threadcount FROM forum WHERE forumid=20 ORDER BY title ASC";
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<FONT SIZE=\"1\" FACE=\"Verdana, Arial, Helvetica, sans-serif\"> °
<A HREF=\"http://www.extremeforums.com/forums/forumdisplay.php?forumid=$latest_array[forumid]\">$latest_array[title]</A> has<b>$latest_array[threadcount]</b> threads</FONT><BR>";
}
?>
Whenever you need me to bow down and kiss your feet in public, let me know!! :cool:
Originally posted by Zothip
Whenever you need me to bow down and kiss your feet in public, let me know!! :cool:
LOL! Heres an update version for you:
<?php
require("/full/path/to/forums/admin/config.php");
$db=mysql_connect($servername,$dbusername,$dbpassw ord);
mysql_select_db($dbname);
if (isset($forumid)==0 or $forumid=="") {
$query = "SELECT forumid,title,threadcount FROM forum ORDER BY title ASC";
}else {
$query = "SELECT forumid,title,threadcount FROM forum WHERE forumid=$forumid";
}
$resultlatest = mysql_query($query,$db);
while ($latest_array = mysql_fetch_array($resultlatest)) {
echo "<FONT SIZE=\"1\" FACE=\"Verdana, Arial, Helvetica, sans-serif\"> °
<A HREF=\"http://www.extremeforums.com/forums/forumdisplay.php?forumid=$latest_array[forumid]\">$latest_array[title]</A> Currently <b>$latest_array[threadcount]</b> threads</FONT><BR>";
}
?>
Just call it like this:
http://www.extremeforums.com/include/forumlist_with_count.inc.php?forumid=2
~Chris
What was wrong with my code? It did exactly what you needed :)
I think a little feet kissing is deserved ;)
Anyway - selecting all the the forumid's and then doing a myqsl_num_rows on it is going to be more accurate then selecting the threadcoutn thing, which is the main difference between the two versions.
You are only selecting numbers as well, so even if you have alot of threads it isn't going to be server intensive.
I like to try to make everything accurate, so I would do it that way :)
Originally posted by Michael
I think a little feet kissing is deserved ;)
Anyway - selecting all the the forumid's and then doing a myqsl_num_rows on it is going to be more accurate then selecting the threadcoutn thing, which is the main difference between the two versions.
You are only selecting numbers as well, so even if you have alot of threads it isn't going to be server intensive.
I like to try to make everything accurate, so I would do it that way :)
Hes trying to get the total number of threads in a particular forum.........so getting the value from the "threadcount" field is most accurate because it tells you exactly how many threads are in that forum
Just my $0.02
~Chris
But threadcount is incremented everytime something is posted, but if there was an error in MySQL and some information was deleted then threadcount would be inaccurate. If you wanted to delete a post through PhpMyAdmin then threadcount would be wrong.
Using a field that is incremented to keep count isn't very accurate.
Originally posted by Michael
But threadcount is incremented everytime something is posted, but if there was an error in MySQL and some information was deleted then threadcount would be inaccurate. If you wanted to delete a post through PhpMyAdmin then threadcount would be wrong.
Using a field that is incremented to keep count isn't very accurate.
Indeed, I'm not quite sure why no one is using this:
<?php
require( "forum/admin/config.php3" );
$db = mysql_connect( $servername, $dbusername, $dbpassword );
mysql_select_db( $dbname );
$query=mysql_query( "SELECT COUNT( * ) AS totalthreads FROM thread WHERE forumid = $forumid" );
$row = mysql_fetch_array( $query );
$totalthreads = $row[ totalthreads ];
echo "$totalthreads total threads";
?>
It's simple.
Easy.
And works.
[Edited by mrogish on 09-11-2000 at 01:22 AM]
That way works as well - one of the books I have says that mysql_num_rows function isa better way, but what you have is better then using the threadcount field.
Originally posted by Michael
That way works as well - one of the books I have says that mysql_num_rows function isa better way, but what you have is better then using the threadcount field.
The only reason why I would use count( ) is that:
1. count is a built in SQL function -- so it's far more efficent than selecting everything in the table.
2. Once you get a result you directly access the array $result[ somevar ]; rather than executing another function (mysql_num_rows( )) -- this would shave off some overhead on PHP's account I would believe.
3. That's what the count( ) function is supposed to do! :)
4. There is no number 4!
But, all of the methods work, it's up to whomever wanted it in the first place to decide! :)
I guess your right, cause SQL functions are faster then PHP functions.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.