View Full Version : For loop troubles
Guest190829
02-03-2005, 10:15 PM
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. :p
Jolten
02-04-2005, 12:05 AM
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.
Guest190829
02-04-2005, 01:12 AM
So every variable that's called must be within the for loop braces?
Jolten
02-04-2005, 01:16 AM
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.
Guest190829
02-04-2005, 02:17 AM
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 .= ?
noppid
02-04-2005, 02:51 AM
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. :p
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-structures.foreach.php
Guest190829
02-04-2005, 03:50 AM
It's not just a simple array like
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.
<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.
noppid
02-04-2005, 04:07 AM
I'm gonna guess that you have to put those in singular variables before passing them to a template to be parsed.
Jolten
02-04-2005, 05:01 AM
I'd agree with noppid. Put them into singular variables first.
hmm if you use array's ill recommand you to use
the function foreach
or each with combine of list...
Guest190829
02-04-2005, 05:15 AM
If you mean singular variables like $ratingcon .= $contents[$i]->rating;
Then I already tried it and it didn't work :ermm:
I'm not too familiar with each and list...
Jolten
02-04-2005, 05:22 AM
for($i =0 ; $i <= sizeof($contents); $i++) {
$ratingcon = $contents[i]->rating;
$var .= $ratingcon;
}
no .= when setting the variable
just a possibility. I could be wrong.
Guest190829
02-04-2005, 05:33 AM
No luck, still nothing showing up. Anything else? I really appreciate everyone's help.
Guest190829
02-05-2005, 05:57 AM
BUMP...anyone? :ermm:
Guest190829
02-06-2005, 06:30 AM
My last bump.... :ermm:
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.