Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 28 Dec 2012, 14:07
swiNz swiNz is offline
 
Join Date: Apr 2002
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 28 Dec 2012, 20:25
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
You might be able to create a new plugin using hook showthread_query and code like:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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.

Last edited by kh99; 28 Dec 2012 at 20:55.
Reply With Quote
  #3  
Old 29 Dec 2012, 08:21
swiNz swiNz is offline
 
Join Date: Apr 2002
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


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 29 Dec 2012, 08:48
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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.

Last edited by kh99; 29 Dec 2012 at 09:02. Reason: added global statement
Reply With Quote
  #5  
Old 29 Dec 2012, 09:49
swiNz swiNz is offline
 
Join Date: Apr 2002
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 29 Dec 2012, 13:56
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
I don't know why that would be - maybe you could try changing the hook_query_fields to


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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 29 Dec 2012, 18:21
swiNz swiNz is offline
 
Join Date: Apr 2002
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)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #8  
Old 29 Dec 2012, 19:51
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
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 29 Dec 2012, 21:29
swiNz swiNz is offline
 
Join Date: Apr 2002
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 03:04.

Layout Options | Width: Wide Color: