• Resolved rogersundstrom

    (@rogersundstrom)


    Having problem with my div format

    This code is working and…

    <?php
    $last_band = null;
    foreach ( $bandinfo as $infoband ) : ?>
    
        <?php if ($last_band != $infoband['band1']): ?>
            <h3><?php echo $infoband['band1']; ?></h3>
        <?php endif; ?>
    
        <?php echo $infoband['lineup']; ?> <?php echo $infoband['year']; ?><br>
    
    <?php
        $last_band = $bandinfo['band1'];
    endforeach; ?>

    it gives me this result
    Band1
    lineup1 year1
    lineup2 year2
    lineup3 year3

    Band2
    lineup1 year1
    lineup2 year2
    lineup3 year3

    Now I want this format instead
    Band1
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    Band2
    <div>
    lineup1 year1
    lineup2 year2
    lineup3 year3
    </div>

    and have tried this code but only get errors like
    Parse error: syntax error, unexpected T_AS in …

    <?php
    $max = count($bandinfo);
    for ( $i = 0; $i < $max; $i++) $bandinfo as $infoband ) :
        $infoband = $bandinfo[$i];
    ?>
    
        <?php if ($i == 0 || $bandinfo[$i-1]['band1'] != $infoband['band1']): ?>
            <h3><?php echo $infoband['band1']; ?></h3>
            <div class="bandinfo">
        <?php endif; ?>
    
        <?php echo $infoband['lineup']; ?> <?php echo $infoband['year']; ?><br>
    
    <?php
         <?php if ($i == $max-1 || $bandinfo[$i+1]['band1'] != $infoband['band1']): ?>
            </div>
        <?php endif; ?>
    endforeach; ?>

    Have anyone some suggestion?

Viewing 11 replies - 16 through 26 (of 26 total)
  • Thread Starter rogersundstrom

    (@rogersundstrom)

    Thanks Scott ??
    It didn’t work. Now I got </div> after first lineup every new Bandx

    I’m using “pretty” as an adverb here.

    Pioneer Web Design

    (@swansonphotos)

    Roger, both WP and many themes or plugins may strip some html tags – please be clear about how you are doing this….

    <?php
    $bands = array();
    
    foreach ( $bandinfo as $band ) {
        if ( !isset( $bands[ $band[ 'band1' ] ] ) )
            $bands[ $band[ 'band1' ] ] = array();
    
        $bands[ $band[ 'band1' ] ][] = $band;
    }
    
    foreach ( $bands as $group => $band_group ) {
    ?>
        <h3><?php echo $group; ?></h3>
    
        <div>
            <?php foreach ( $band_group as $band ) { ?>
                <?php echo $band[ 'lineup' ]; ?> <?php echo $band[ 'year' ]; ?><br>
            <?php } ?>
        </div>
    <?php
    }
    ?>

    Just updated my reply with a fix to the logic, should be good now.

    Thread Starter rogersundstrom

    (@rogersundstrom)

    Didn’t work out. Now I get this

    Band1
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band4
    <div>
    Lineupx Yearx
    </div>

    Band1
    <div>
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    Lineupx Yearx
    </div>

    Band2
    <div>
    Lineupx Yearx
    </div>

    Band3
    <div>
    Lineupx Yearx
    </div>

    Band4
    <div>
    Lineupx Yearx
    </div>

    Band5
    <div>
    Lineupx Yearx
    </div>

    How is your code being called? Can you provide the rest?

    Thread Starter rogersundstrom

    (@rogersundstrom)

    In this case Band1 have 6 lineups
    and Band2-Band5 have 1 lineup

    Now he list bands more than one and in a weird order.

    Where are you getting $bandinfo?

    Resolved with Roger in our ‘not good’ plugin’s chat room in real time.

    Thread Starter rogersundstrom

    (@rogersundstrom)

    Here is the working code ??

    <?php $bands = array(); ?>
    
    <?php foreach ( $bandinfo_data[0] as $bandsattning => $bandinfo ) : ?>
    <?php foreach ( $bandinfo as $band ) {
        if ( !isset( $bands[ $band[ 'band1' ] ] ) )
            $bands[ $band[ 'band1' ] ] = array();
    
        $bands[ $band[ 'band1' ] ][] = $band;
    }
    ?>
    <?php endforeach; ?>
    
        <?php
    
    foreach ( $bands as $group => $band_group ) {
    ?>
        <h3><?php echo $group; ?></h3>
    
        <div>
            <?php foreach ( $band_group as $band ) { ?>
                <?php echo $band[ 'lineup' ]; ?> <?php echo $band[ 'year' ]; ?><br>
            <?php } ?>
        </div>
    <?php
    }
    ?>
Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘div format’ is closed to new replies.