View Full Version : How Would I pull Information From vBulletin?
Pc 1203
08-01-2007, 04:33 PM
Hi All,
I'm wondering how would I pull information from vBulletin? I would like to pull:
Username
Posts
And Some Additional Information
- Pc1203
Sorry, the pages are outside of vBulletin.
Kirk Y
08-01-2007, 06:12 PM
Are you trying to display this information on a page within vBulletin or are you using it outside of vBulletin?
Pc 1203
08-01-2007, 06:15 PM
A page outside of vBulletin.
- Pc1203
Kirk Y
08-01-2007, 06:25 PM
This might of use to you: https://vborg.vbsupport.ru/showthread.php?t=108026
Pc 1203
08-01-2007, 06:31 PM
Well, that really isn't what I wanted. I wanted to pull a users posts into an external page. And, yes I checked, vBExternal doesn't do what I'm thinking of.
- Pc1203
Kirk Y
08-01-2007, 06:35 PM
What are you trying to do specifically, because I've used a modified vBExternal in the past to display trimmed posts, with the Author's Username, and date of posting on an external page.
Pc 1203
08-01-2007, 06:38 PM
Ok, this is what I'm trying to do. I'm trying to create a small profile system for my website. In it somewhere, it says the users posts, join date, username, and some custom profile fields. Hope this is better.
- Pc1203
Kirk Y
08-01-2007, 06:44 PM
Well it's really just a matter of querying the database for the relevant information.
Place the following at the very top of the pages you're displaying information on; make sure they're PHP files as well.
<?php
chdir('/path/to/forum');
require_once('/path/to/global.php');
?>Then you're free to use the DB class to retrieve information.
Example:
$stats = $db->query_read("SELECT threadcount, replycount FROM " . TABLE_PREFIX . "forum");
while ($forum = $db->fetch_array($stats))
{
$threads += $forum['threadcount'];
$posts += $forum['replycount'];
}
$threads = vb_number_format($threads);
$posts = vb_number_format($posts);
Pc 1203
08-01-2007, 06:46 PM
Ok, Thanks alot!
// I would add rep but I guess it's disabled.
- Pc1203
EDIT: I get a blank page after trying this code:
<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');
?>
<html>
<head>
</head>
<body>
Test
<?php
$stats = $db->query_read("SELECT threadcount, replycount FROM " . TABLE_PREFIX . "forum");
while ($forum = $db->fetch_array($stats))
{
$threads += $forum['threadcount'];
$posts += $forum['replycount'];
}
$threads = vb_number_format($threads);
$posts = vb_number_format($posts);
$stats
?>
</body>
</html>
EDIT2: Uh-Oh. I guess I miss-lead you. I want to display a USERS posts/join date/if online/not, ect. Sorry.
- Pc1203
Pc 1203
08-02-2007, 07:55 PM
Bump
- Pc1203
Opserty
08-02-2007, 08:12 PM
Something like this:
// Add the usual require stuff here
$wanted_userid = 9; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);
$posts = $userinfo['posts'];
// $joindate = $userinfo['joindate']; // Unformatted
$joindate = vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug
ef
(Untested)
Pc 1203
08-02-2007, 08:23 PM
Ok, but would I need to include any files like global.php to get that to work?
- Pc1203
Opserty
08-02-2007, 08:27 PM
Yes you will need to include the global.php file from the main forum directory.
Pc 1203
08-02-2007, 08:33 PM
I just get a blank page. Here is my code:
<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');
// Add the usual require stuff here
$wanted_userid = 9; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);
$posts = $userinfo['posts'];
// $joindate = $userinfo['joindate']; // Unformatted
$joindate = vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug
$joindate
?>EDIT: Stupid Me! I forgot to use the print command. It works! Thanks Alot! Do you know how to get custom profile fields, though?
EDIT2: When I look at join date I get "1177448760" for my user....
EnIgMa1234
08-02-2007, 08:36 PM
You need to add the variables to a template
Kirk Y
08-02-2007, 08:38 PM
You need to use the vbdate() function to convert the timestamp into a readable format.
Pc 1203
08-02-2007, 08:41 PM
Ok, I did that and I'm still getting the same thing. Here is my code:
<?php
chdir('/home/penguink/public_html/forums');
require_once('/home/penguink/public_html/forums/global.php');
// Add the usual require stuff here
$wanted_userid = $_GET['u']; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);
$posts = $userinfo['posts'];
$username = $userinfo['username'];
//$joindate = $userinfo['joindate']; // Unformatted
$joindate = vbdate($userinfo['joindate']); // Formatted date e.g. Mon 29th Aug
print "<h1>$username</h1>";
print "Posts: $posts";
print "<br />";
print "$username Joined On: $joindate";
?>
It outputs:
Pc1203
Posts: 1044
Pc1203 Joined On: 1177448760
- Pc1203
EnIgMa1234
08-02-2007, 08:41 PM
This is how to use vbdate.
vbdate($vbulletin->options[dateformat], $userinfo['joindate']);
Kirk Y
08-02-2007, 08:44 PM
Sample query for profile fields:
$fields = $vbulletin->db->query_first("SELECT * FROM userfield WHERE userid =".$userid);
Then you can use $fields['fieldX'] to retrieve a particular field.
Also, you should look into cleaning the variables you're using in queries - or you'll leave this page open to SQL injection.
Pc 1203
08-02-2007, 08:45 PM
Ok Thanks EnIgMa1234! The date works now. Any ideas on how to get some custom profile fields?
- Pc1203
EDIT: Ok, Kirk Y. I'll try that. Also you said I should change the variables, is that what you meant?
EnIgMa1234
08-02-2007, 08:47 PM
$fields = $vbulletin->db->query_first("SELECT * FROM userfield
WHERE userid = '" . $userid . "');
Opserty
08-02-2007, 08:59 PM
Kirk/Enigma: Does fetch_userinfo() not fetch custom fields?
Kirk Y
08-02-2007, 09:22 PM
I've never used it, you may be right.
Pc 1203
08-02-2007, 09:26 PM
Also, you should look into cleaning the variables you're using in queries - or you'll leave this page open to SQL injection.
What do you mean by "cleaning the variables"?
- Pc1203
Kirk Y
08-02-2007, 09:38 PM
If Opserty is correct in you being able to simply use $userinfo['fieldX'] in place of the query I suggested, you don't need to worry about cleaning the $_GET superglobal.
Pc 1203
08-02-2007, 09:45 PM
Yup, Opserty is correct. So I don't have to worrie about anything then, right?
- Pc1203
Kirk Y
08-02-2007, 09:53 PM
No, as long as you're not querying anything more.
Pc 1203
08-02-2007, 10:03 PM
Ok, and for future reference here is the source:
<?php
chdir('/path/to/your/forums');
require_once('/path/to/your/forums/global.php');
// Add the usual require stuff here
$wanted_userid = $_GET['u']; // The user id of the user you want the data from
$userinfo = fetch_userinfo($wanted_userid);
$posts = $userinfo['posts'];
$username = $userinfo['username'];
$joindate = vbdate($vbulletin->options[dateformat], $userinfo['joindate']);
?>
<h1>
<?php print $username; ?>
</h1>
Posts: <?php print $posts; ?><br />
<?php print $username; ?> Joined On: <?php print $joindate; ?><p>
Custom Profile Field #1: <?php print $userinfo['field4']; ?><br />
**NOTE** Change "chdir('/path/to/your/forums');" to the full path to your forums directory and "require_once('/path/to/your/forums/global.php');" to the full path to the global.php file.
- Pc1203
Dismounted
08-03-2007, 10:42 AM
$wanted_userid = $_GET['u'];
Should really be.
$wanted_userid = intval($_GET['u']);
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.