Query user info
Forum rules
Only post tools related to modding in here, simple.
Only post tools related to modding in here, simple.
-
- Supporter
- Posts: 316
- Joined: 18 Sep 2007, 14:35
- Real name: David
- Contact:
Query user info
Here's a function I made that might be useful for larger MODs to include in a functions file. It is used for querying the users table to get user info. It isn't hard to make your own little thing like this, but you could greatly reduce the amount of code if you use a function to get user info every time instead of writing it all out, plus save your sanity. You can either specify a specific user_id, an array of user_ids, or you can change $where to make it get a certain type of user, eg one that has registered before a certain date. The code does 'WHERE ' . $where, so you don't need to include "WHERE" at the beginning, or a space. I am posting the code here in a zip, because of some stupid errors with the syntax highlighting having a limit to the number of characters, or something like that...
- Attachments
-
- query_user_stats.zip
- (1.28 KiB) Downloaded 139 times
Last edited by harmlessgoat22 on 19 Aug 2008, 13:54, edited 1 time in total.
That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever
Re: Query user info
harmlessgoat22 wrote:I am posting the code here in a zip, because of some stupid errors with the syntax highlighting having a limit to the number of characters, or something like that...
Yeah, it's a PHP bug.
I remember phpBB2 had something like this, less complex though.
I'd use a function_exists check here:
Code: Select all
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
<> is used in SQL, the guest user has a constant. It should be: != ANONYMOUS.
Code: Select all
if ($user_id <> 0)
You might as well add this before the if().
Code: Select all
$ranks = $cache->obtain_ranks();
This is totally crazy
Code: Select all
$data = $row;
$data[$user_id] = $data = array_merge($data, array(
And so is this
Code: Select all
$data[$user_id] = $row;
$data[$user_id] = array_merge($data[$user_id], array(
Oh, and this too
Code: Select all
if ($where == '')
{
$where = '1=0';
}
You are not using $user_ids at all.
I'd find it better if you could pass a row from the users table to the function and it would return you an array of processed userdata. Let the user handle the querying himself... or make a separate function for that.
Donate to phpBBModders.net - we're poor!
-
- Supporter
- Posts: 316
- Joined: 18 Sep 2007, 14:35
- Real name: David
- Contact:
Re: Query user info
Code: Select all
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
Will do.
First of all, the ANONYMOUS constant is defined as 1, not 0, second, I'm not checking if it is anonymous, it's checking if the user wants to use the other parameters, instead of that.
Code: Select all
$data = $row;
$data[$user_id] = $data = array_merge($data, array(
How is that so crazy? $data = $row makes sure that all the information is in there, raw and untouched. It also has vars such as user_my_mods_new_column so that the MOD developer wouldn't have to edit this file to make it work. I also had a very good reason for doing this: $data[$user_id] = $data = etc. : but if you like, it will be removed...
Code: Select all
if ($where == '')
{
$where = '1=0';
}
That makes sure that if the user didn't put anything for where, it doesn't crash by having "SELECT * FROM USERS_TABLE WHERE ", it just doesn't get any results. I guess I could just do a return on that, but then if the user is expecting to get an array back, even if the array is empty, they may receive an error.
Now, I remembered to have user_ids work..."$db->sql_in_set" function.
I'm updating the first post now...
That's like, I can't beat my neighbor in an argument, so instead I kill his dog.
-Best English Teacher Ever