Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-28-2012, 02:07 PM
swiNz swiNz is offline
 
Join Date: Apr 2002
Location: Purmerend, Netherlands
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default extra postbit info from database

Hello,

I've got a question for you, i'm running a car website and i'm using the MOD D.T.O. Garage, in that mod you can add your car and put some information in your own profile like car make, model, year etc.

Now i want to show the users car make, model and year (if existing) in the postbit.

Do you guys have any idea how to do that? The DTO table where the vehicle information is is called "DTO_garage_vehicle" and the info i want are 'year' 'make' and 'model' in that table!

Hope you can help me out!
Reply With Quote
  #2  
Old 12-28-2012, 08:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You might be able to create a new plugin using hook showthread_query and code like:
Code:
$hook_query_fields .= " , DTO_garage_vehicle.* ";
$hook_query_joins .= " LEFT JOIN DTO_garage_vehicle ON (DTO_garage_vehicle.userid = post.userid) ";

Then in the postbit (or postbit_legacy) template use {vb:var post.year}, {vb:var post.make}, etc.

The above assumes that DTO_garage_vehicle has a userid field.
Reply With Quote
Благодарность от:
swiNz
  #3  
Old 12-29-2012, 08:21 AM
swiNz swiNz is offline
 
Join Date: Apr 2002
Location: Purmerend, Netherlands
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, that works like a charm!
Now i only need to put a filter on it, i want to limit the query to only one vehicle (latest added) because a user can have multiple cars.

i tried the code

PHP Code:
$hook_query_fields .= " , DTO_garage_vehicle.* ";
$hook_query_joins .= " LEFT JOIN DTO_garage_vehicle ON (DTO_garage_vehicle.userid = post.userid) ORDER BY `DTO_garage_vehicle`.`time_added` DESC LIMIT 0,1"
But this code gives me an error, sorry if i'm being noob here, never worked with LEFT JOIN (i only know the simple querys)
Reply With Quote
  #4  
Old 12-29-2012, 08:48 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, right. I should have thought that a user might have more than one vehicle. I'm not exactly an sql expert myself, but I don't know of any way to use a join to handle that situation. You'll probably have to add another query for each user to get their vehicle records.

At postbit_display_complete you could do something like:
Code:
global $vbulletin;

if ($vehicle = $vbulletin->db->query_first_slave("SELECT year, make, model FROM DTO_garage_vehicle WHERE userid = " . $post['userid']))
{
    $post['year'] = $vehicle['year'];
    $post['make'] = $vehicle['make'];
    $post['model'] = $vehicle['model'];
}

or if you wanted to show all of a user's vehicles you could use query_read_slave() instead and have a while loop to get each vehicle, then maybe save an array and use a vb:each loop in the template.

Also I should mention that this adds an additional query for each post. I know people try to limit the number of queries being done to make their site run faster, but I don't know how much of an effect this would have. It probably depends a lot on how busy your site is and what kind of server you have. But if it's a problem you could probably do something like make a custom profile field with the info pre-formatted, and update it when the user changes their vehicle information. Then you would only need to use the profile field in the postbit (and it would already be available without any extra queries).

Edit: the code I posted above was orignially missing the "global" line.
Reply With Quote
  #5  
Old 12-29-2012, 09:49 AM
swiNz swiNz is offline
 
Join Date: Apr 2002
Location: Purmerend, Netherlands
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've got some problem with the first piece of code (ur first post)
When i run that "plugin" some members "disappear" in the forums (they show up as guest where they posted), any idea why? (could it have something to do with the option people can set if their garage is visible for everybody or for friends only? )

Edit:

It appears that this people who show up as guest don't have a garage (car) added to their profile..
Reply With Quote
  #6  
Old 12-29-2012, 01:56 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know why that would be - maybe you could try changing the hook_query_fields to

Code:
$hook_query_fields .= " , DTO_garage_vehicle.year, DTO_garage_vehicle.make, DTO_garage_vehicle.model,  ";

but like I mentioned, I think that method's going to duplicate posts if someone has more than one car.
Reply With Quote
  #7  
Old 12-29-2012, 06:21 PM
swiNz swiNz is offline
 
Join Date: Apr 2002
Location: Purmerend, Netherlands
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yeah, that's going to give a problem with more garages per member, i've tried to check if a user has a garage with the folowing code (but that doesnt work also)

PHP Code:
$counter mysql_query("SELECT COUNT(*) AS id FROM DTO_garage_vehicle WHERE userid = post.userid");
$num mysql_fetch_array($counter);
$count $num["id"];

if (
$count 0) {

}
else {

$hook_query_fields .= " , DTO_garage_vehicle.* ";
$hook_query_joins .= " LEFT JOIN DTO_garage_vehicle ON (DTO_garage_vehicle.userid = post.userid) ";


Reply With Quote
  #8  
Old 12-29-2012, 07:51 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, the problem is that at that point you have no $post['userid'] yet - what we're trying to do is add to the query that gets the posts, to save doing extra queries. If you're going to do an extra query anyway, then you might as well try what I posted in my second post.
Reply With Quote
  #9  
Old 12-29-2012, 09:29 PM
swiNz swiNz is offline
 
Join Date: Apr 2002
Location: Purmerend, Netherlands
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tried your code, but i had to edit it a little bit..

Thank you so much for your help, now i also understand how the vbulletin system is working!

It you want to know what i'm using now:

PHP Code:
global $vbulletin;

if (!
$post['userid']) {
    
// This is for the deleted (guest) users on the forum, they don't have a userid, so i made them one :D
    
$usersid 1292;
}
else {
    
$usersid $post['userid'];
}

if (
$vehicle $vbulletin->db->query_first_slave("SELECT year, make, model, color, packages FROM DTO_garage_vehicle WHERE userid = " $usersid))
{
    
$post['year'] = $vehicle['year'];
    
$post['make'] = $vehicle['make'];
    
$post['model'] = $vehicle['model'];
    
$post['color'] = $vehicle['color'];
    
$post['packages'] = $vehicle['packages'];
}
else {
    
// I also wanted to show people if a member has no garage :)
    
$nogarage TRUE;

Reply With Quote
2 благодарности(ей) от:
I AmishaR I, patrick91
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:56 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04392 seconds
  • Memory Usage 2,262KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (3)post_thanks_box_bit
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete