Display "Back to top" anchor within while loop

Hey,

Take a look at the following page:

http://www.freemanholland.com/hanging/product-range/?catID=1&type=White%20wine

You can see a list of products and “Quicklinks” at the top of the page which takes users to the appropriate product listing.

Now, i need to a “back to top” link at the end of every set of products, so for example you can see “Aromatic”, so before “Aromatic Magnum” starts i need to add a back to top link.

Now i have had to iterate through each field to display the results, my code is shown below:


 <?
        if($brandrow['brandCount'] != 1){ 

        //start iterating   
        $saveBrand = '';
        $i=0;
        ?>        
        <a name='top'></a>
        
            <div id="quicklinks">
            <h3>Quicklinks</h3>
            <ul>        

            <?            
            while($rowlinks = mysql_fetch_array($productsOne)){ 
            echo "<li><a href='#$rowlinks[brand]'>$rowlinks[brand] &raquo;</a></li>";
            }
            ?>
            </ul>
            </div>

            <div class="line"></div>
            <table cellspacing="0" width="100%">
                <thead>
                    <tr>
                       <th style="width: 400px; text-align:left; color:#b92923; font-weight:bold">Name</th>
                       <th style="width: 103px; text-align:left; color:#b92923; font-weight:bold">Cost:</th>
                       <th style="color:#b92923; font-weight:bold; text-align:left;">Country</th>
                    </tr>
                </thead>

            <?

                while($row = mysql_fetch_array($products)) {  
                    if($row['brand'] != $saveBrand) {           
                            echo "<tr class='tdrow' style='font-size: 16px; height: 20px; line-height: 38px; border-bottom:1px solid #999'><td><a name='$row[brand]'></a> $row[brand]</td></tr>";               
                            $cycle = false;
                            $saveBrand = $row['brand'];   
                        }                      
                    echo "<tr class=\\"row$i\\"><td class='tdrow'>$row[name]</td><td class='tdrow'>&pound;$row[cost]</td><td class='tdrow'>$row[country]</td></tr>"; 
                    $i++;
                    $i = $i % 2;  
                } 
            ?>
            </table>
        <?  
        }

Can you see where i need to add this?

Thanks again

<? 
        if($brandrow['brandCount'] != 1){ 

        //start iterating    
        $saveBrand = ''; 
        $i=0; 
        ?>         
        <a name='top'></a> 
         
            <div id="quicklinks"> 
            <h3>Quicklinks</h3> 
            <ul>         

            <?             
            while($rowlinks = mysql_fetch_array($productsOne)){ 
            echo "<li><a href='#$rowlinks[brand]'>$rowlinks[brand] &raquo;</a></li>"; 
            } 
            ?> 
            </ul> 
            </div> 

            <div class="line"></div> 
            <table cellspacing="0" width="100&#37;"> 
                <thead> 
                    <tr> 
                       <th style="width: 400px; text-align:left; color:#b92923; font-weight:bold">Name</th> 
                       <th style="width: 103px; text-align:left; color:#b92923; font-weight:bold">Cost:</th> 
                       <th style="color:#b92923; font-weight:bold; text-align:left;">Country</th> 
                    </tr> 
                </thead> 

            <? 

                /*while($row = mysql_fetch_array($products)) {   
                    if($row['brand'] != $saveBrand) {            
                            echo "<tr class='tdrow' style='font-size: 16px; height: 20px; line-height: 38px; border-bottom:1px solid #999'><td><a name='$row[brand]'></a> $row[brand]</td></tr>";                
                            $cycle = false; 
                            $saveBrand = $row['brand'];    
                        }                       
                    echo "<tr class=\\"row$i\\"><td class='tdrow'>$row[name]</td><td class='tdrow'>&pound;$row[cost]</td><td class='tdrow'>$row[country]</td></tr>"; 
                    $i++; 
                    $i = $i % 2;   
                }*/
                $prevRow = null;
                while ($row = mysql_fetch_assoc($products)) {
                      if ($prevRow['brand'] != $row['brand']) {
                           if ($prevRow !== null) 
                               // echo your top link

                           // your echo      
                      }
                      
                      // your other echo

                     $prevRow = $row;
                     $i = empty($i) ? 1 : 0;
                }
            ?> 
            </table> 
        <?   
        }

That should work fine. It just echoes the top link before you echo the title for your categories.

EDIT: made a small change

Hey,

Thanks, that worked perfectly, i can’t believe i didn’t think of that :lol:

Thanks again