Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Useful function when you are coding addons
hamoe
Join Date: Jul 2002
Posts: 10

oregon
by hamoe hamoe is offline 27 Jul 2002

Last night I coded the main page for http://www.fexboards.com, and before that I coded the tutorial database for that same site (organized very similar to this sites hack section, although I believe coded quite differently). I knew I was going to have to deal with a lot of repeating-element templates. By repeating-element templates, I mean templates such as the infamous postbit template, something which when its finally used, will be echoed out many times in a row in accordance with the results of a database query. The function I wrote has you supply a comma separated list of variables as they would appear in the database query, your master template name, your subtemplate name, the table(s) present in the from clause of the query, and the conditions under which the selection will take place (the where clause, you can also include order by and group by stuff here).

An example of its use is as follows:

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

That one function call right there will store all the iterations of the mainpage_top10posters template, filled with the top 10 posters' information, into $mainpage[top10posters]. That means after you run this you can just include your final template that just echoes out $mainpage[top10posters] where its needed.

The main limitation is that you cannot do any processing on the variables. If you wanted to loop through posts and you wanted to parse the pagetext with bbcodeparse(), you would have to hack up the function or just forget about using it. Nonetheless, I have found it pretty useful.

Comments/criticism/suggestions appreciated. The function is attached.
Attached Files
File Type: php loop_template.func.php (1.9 KB, 31 views)
Views: 2898
Reply With Quote
Comments
  #2  
Old 29 Jul 2002, 04:50
hamoe hamoe is offline
 
Join Date: Jul 2002
I just realized this would probably do better in the Hacking Hints and Tips forum. If some bored mod feels like moving it for me it would be appreciated
Reply With Quote
  #3  
Old 29 Jul 2002, 09:14
Chen's Avatar
Chen Chen is offline
 
Join Date: Sep 2001
Umm, this could be written a lot shorter and faster...


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

__________________
Chen Avinadav
Formerly vBulletin.org Owner and Founder

chen@avinadav.com
Reply With Quote
  #4  
Old 29 Jul 2002, 09:38
hamoe hamoe is offline
 
Join Date: Jul 2002
Thanks a lot, firefly. I feel really dumb about not realizing that I could have gotten fieldnames from the mysql_fetch_array() results. I haven't gotten used to the functions in vb quite yet, so I can almost justify my unneeded usage of output buffering. And nice call on defaulting the last argument to ''.

I still think this function is pretty useful, but use firefly's revised version, does the same thing but with less code and less load
Reply With Quote
  #5  
Old 31 Jul 2002, 00:31
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
How would I apply this?
I want to change

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

to that.

Thanks
Drk
__________________
ZunePoint.com
Reply With Quote
  #6  
Old 31 Jul 2002, 02:12
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
bump

Drk
__________________
ZunePoint.com
Reply With Quote
  #7  
Old 31 Jul 2002, 02:18
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Real name: Chris Murphy, BSc
Arunan -

Shouldnt it be?


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

???

Satan
Reply With Quote
  #8  
Old 31 Jul 2002, 02:20
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
It is, but its not repeating the link in reviews.php

Drk
__________________
ZunePoint.com
Reply With Quote
  #9  
Old 31 Jul 2002, 02:25
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Real name: Chris Murphy, BSc
Ok...But at least it calls the right variable

Its a start...

Now we just need help

Satan
Reply With Quote
  #10  
Old 31 Jul 2002, 02:35
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
Chen? Hamoe? come on guys

Drk
__________________
ZunePoint.com
Reply With Quote
  #11  
Old 31 Jul 2002, 02:54
hamoe hamoe is offline
 
Join Date: Jul 2002
Hey I'm here. What I am wondering is why you don't just have that link in your template file....


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


Can you not just have that link that I took out in your template? Here is how the function call would look:

loop_template("*", "reviews","list", "reviews");

In your template the variables will be available to you like this:

$reviews[list_fieldname]

All other variables you want to use that arent taken from the mysql query are just available how you would expect them.
Reply With Quote
  #12  
Old 31 Jul 2002, 02:57
DrkFusion's Avatar
DrkFusion DrkFusion is offline
 
Join Date: Nov 2001
Thanks man, you are the coolest person around, can you help me further on aim, if you have it

my friend sat ScapeStudio, I am at his house

Thanks
__________________
ZunePoint.com
Reply With Quote
  #13  
Old 31 Jul 2002, 03:14
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Real name: Chris Murphy, BSc
Cool...

Satan
Reply With Quote
  #14  
Old 31 Jul 2002, 05:24
SaintDog SaintDog is offline
 
Join Date: Nov 2001
Location: Tennessee
Real name: Jonathan
Originally posted by hamoe
I just realized this would probably do better in the Hacking Hints and Tips forum. If some bored mod feels like moving it for me it would be appreciated
Bored....Moved....


- SaintDog
Reply With Quote
  #15  
Old 01 Aug 2002, 07:36
hamoe hamoe is offline
 
Join Date: Jul 2002
lol, thanks saintdog, i knew someone would get bored eventually
Reply With Quote
Reply



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

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 01:47.

Layout Options | Width: Wide Color: