The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
help with foreach loop please?
What i want it to do is this: for each artisttype that is returned, i want to eval the "erc_artistroster_typerow" template and within that it cycles through the "erc_artistroster_rpt" template using the while loop.
Having some difficulty though with the foreach loop below... here's my code: PHP Code:
I think i need to use a foreach loop, however i'm just getting a blank page now |
#2
|
||||
|
||||
The array you are feeding the foreach loop is only one row ($artisttype).
Are your artist types coming from the database? |
#3
|
||||
|
||||
You're also missing a bracket at the end of your foreach:
PHP Code:
You also don't need array() around it in the foreach if it is going to be an array. |
#4
|
||||
|
||||
You also can't use $artist['image'] and the rest of those query results outside the while loop, nor before it as you are doing.
|
#5
|
||||
|
||||
Quote:
I'm getting them to display as needed within the "erc_artistroster_rpt" template that is contained in the while loop, however when i try to use the foreach loop to group the artists by artisttype and place each group within the "erc_artistroster_typerow" template, i just get the blank screen of death! Quote:
Quote:
|
#6
|
||||
|
||||
This bit
PHP Code:
I haven't looked into great detail as to what you are trying to do. But, it seems your foreach loop needs to be inside the while loop not the other way around. |
#7
|
||||
|
||||
thanks jumpd, i actually acheived what i want through the use of inserting an if...else statement to change the controls for the <if> statements within the template.
Problem I am having now however is that the first instance of the $artisttype var (which occurrs in the first group of artisttypes) is not outputting the correct value for those artisttypes. Here's my php now... PHP Code:
HTML Code:
<if condition="$isnewtype"> </tr> </table> </td> </tr> </table> <br> <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center"> <tr> <td class="tcat">$artisttype $vbphrase[artists]</td> </tr> <tr> <td class="alt1" align="left" width="100%"><a name="$artisttype"></a> <table> <tr valign="top"> </if> <td class="ercshowartists" align="center"> <a href="artist.php?do=artist&artistid=$artist[artistid]"> <img src="forum/modules/erc_thumbnailimage.php?artistimageid=$artist[artistimageid]&width=220" alt="$artist[artisttitle]" border="0"> </a><br><br> $artist[artisttitle] $choicecounter </td> <if condition="$newrow == 1"> </tr><tr valign="top"> <td><img height="4" src="$vboptions[bburl]/clear.gif"></td> </tr><tr valign="top"> <else /> <td><img width="4" src="$vboptions[bburl]/clear.gif"></td> </if> HTML Code:
<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center"> <tr> <td class="tcat">$artisttype $vbphrase[artists]</td> </tr> <tr> <td class="alt1" align="left" width="100%"><a name="$artisttype"></a> <table> <tr valign="top"> $artists </tr> </table> </td> </tr> </table> |
#8
|
||||
|
||||
What do you mean by "not outputing the correct value"?
What's it outputing? Can an artist be in more than one artist type? It most likely has something to do with your query structure. Joining to a table where multiple relationships with data in the first exist will cause problems. GROUP BY has it's own issues if not used properly as well. Maybe you need to call from the artisttype table and join the artists table to it. It's really hard to say without a detailed explanation of what you are trying to accomplish and without seeing the table structures. |
#9
|
||||
|
||||
I figured out what the problem was, i had my IF statements within the WHILE statements in the incorrect order, whcih was incorrectly controlling when the if conditionals within the template were passing values or not.
also, the query structure is working fine now but i did end up removing the GROUP BY statement to simplify it. Thanks for your help |
#10
|
||||
|
||||
Another thing to simplify the query is that when you are joining two tables by collumns of the same name, as you are. Such as
PHP Code:
PHP Code:
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|