Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2005, 10:15 PM
Guest190829
Guest
 
Posts: n/a
Default For loop troubles

I need to make a for loop to access the contents of an array, but I don't know where to put it or if vbulletin has a special syntax for it.

The loop is

for($i=0; $i < sizeof($contents); $i++)

then I access the contents of the array inside a table.

Do I put in the template? Or somewhere else?

Any help will be greatly appreciated.
Reply With Quote
  #2  
Old 02-04-2005, 12:05 AM
Jolten Jolten is offline
 
Join Date: Mar 2004
Posts: 749
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
 for($i =0 ; $i <= sizeof($contents); $i++)  {
 $var .= "whatever";
 $var2 .= "more Whatever"
}
You'll need to put that in an appropriate php script. Then in your template use $var and $var2 or whatever variables you're calling with the for loop.
Reply With Quote
  #3  
Old 02-04-2005, 01:12 AM
Guest190829
Guest
 
Posts: n/a
Default

So every variable that's called must be within the for loop braces?
Reply With Quote
  #4  
Old 02-04-2005, 01:16 AM
Jolten Jolten is offline
 
Join Date: Mar 2004
Posts: 749
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want the variables to change based on the count, yes. The way I have it coded above with the .= the variable will simply be repeated for each count. so if the count = 4 placing $var in your template would render the word Whatever 4 times. and placing $var2 in your template will render more Whatever 4 times as well.
Reply With Quote
  #5  
Old 02-04-2005, 02:17 AM
Guest190829
Guest
 
Posts: n/a
Default

well the variable i have to access is $contents[$i]->rating

And I tried doing $rating .= $contents[$i]->rating

but that didn't work....

I'm getting the array from an included file, would I have to change all the variables in there from = to .= ?
Reply With Quote
  #6  
Old 02-04-2005, 02:51 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Danny.VBT
I need to make a for loop to access the contents of an array, but I don't know where to put it or if vbulletin has a special syntax for it.

The loop is

for($i=0; $i < sizeof($contents); $i++)

then I access the contents of the array inside a table.

Do I put in the template? Or somewhere else?

Any help will be greatly appreciated.
PHP Code:
for($i=0$i sizeof($contents); $i++) 
That looks like you're walking through a file byte by byte in C.

If you have an array look at foreach()...

http://us4.php.net/manual/en/control...es.foreach.php
Reply With Quote
  #7  
Old 02-04-2005, 03:50 AM
Guest190829
Guest
 
Posts: n/a
Default

It's not just a simple array like

PHP Code:
array( '1''2''3''4''5''6' ); 
and the actual code to it is not my own because i'm only intergrating it into vbulletin. So a for each loop would be too difficult.

I just need to a detail way to access the variable of the array to the templates.


Code:
<td> $contents[$i]->rating</td><td> $contents[$i]->runtime</td>
etc...etcc...all works when it's harcoded with the php file, it just the template that messes it up.
Reply With Quote
  #8  
Old 02-04-2005, 04:07 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm gonna guess that you have to put those in singular variables before passing them to a template to be parsed.
Reply With Quote
  #9  
Old 02-04-2005, 05:01 AM
Jolten Jolten is offline
 
Join Date: Mar 2004
Posts: 749
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd agree with noppid. Put them into singular variables first.
Reply With Quote
  #10  
Old 02-04-2005, 05:05 AM
miz miz is offline
 
Join Date: Mar 2003
Posts: 416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm if you use array's ill recommand you to use
the function foreach
or each with combine of list...
Reply With Quote
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 04:23 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04215 seconds
  • Memory Usage 2,248KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (6)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_imicons
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete