troubleshooting Question

Different headlines in a table

Avatar of Peter Kroman
Peter KromanFlag for Denmark asked on
PHP
6 Comments1 Solution90 ViewsLast Modified:
Hi,

I have a need to be able to show different headlines depending on the search result in the database.
I have made the code pasted in below, but it give me the problem that when I have a search that have more than one result in the "Type" column, I get the headline displayed at every row in the table.

Try it here - write e.g. Odense Odense in the searchfield. http://kroweb.dk/gfdev/ft_raw2/#

Is there a way that i create a separate headline when I have more than one result in the "Type" column, and at the same time keep the possibilities to differentiate the headlines represented in the code below?

                               <!-- Have we ran a query -->
                               <?php if (isset($results)): ?>

                               <!-- Do we have any results -->
                               <?php if ($results->num_rows): ?>

                               <table id="myTable" class="table">
                                <colgroup>
                            </colgroup>

                            <tr>
                                <!-- Loop through the results of the query -->    
                                <?php while ($row = $results->fetch_object()): ?>
                                


                                <?php if ($row->Type =='Købstad'): ?>

                                <th>&nbsp;</th> <th>Amt By Gade</th> <th>Amt</th> <th>Aar</th> <th>Type</th> <th>Gade (1860)</th> <th>Matr. nr. (1860)</th> 

                            <?php elseif ($row->Type == 'Hovedstaden'):?>

                            <th>&nbsp;</th> <th>Amt By Gade</th> <th>Amt</th> <th>Aar</th> <th>Type</th> <th>Gade (1860)</th> <th>Matr. nr. (1860)</th> 

                            <?php else:
                            if ($row->Type =='Landdistrikt'): ?>
                            
                            <th>&nbsp;</th> <th>Amt Herred Sogn</th> <th>Amt</th> <th>Aar</th> <th>Type</th> <th>Gade (1860)</th> <th>Matr. nr. (1860)</th> 

                        <?php endif; ?>
                    <?php endif; ?>



                </tr>


                <!-- Links for the individual rows -->    
                <?php
                $link1 = sprintf("<a href='%s' target='_blank'>%s</a>", $row->URL, $row->AmtHerredSognGade); 
                $link2 = sprintf("<a href='%s' target='_blank'>%s</a>", $row->Infourl, $row->Info);
                $link3 = sprintf("<a href='%s' target='_blank'>%s</a>", $row->Infourl, $row->Gade);
                $link4 = sprintf($row->AmtHerredSognGade);
                ?>

                <?php if ($row->Collapse == 'p'): ?>
                <!-- We have a parent row -->

                <tbody class='toggle' >
                    <tr class="expander">
                        <td><span class='toggle'></td>
                        <td><?php echo (!empty($row->URL)) ? $link1 : $link4 ?></td>
                        <td><?php echo $row->Amt ?></td>             
                        <td><?php echo $row->Aar ?></td>
                        <td><?php echo $row->Type ?></td>   
                        <td><?php echo $row->Gade ?></td>            
                        <td><?php echo $row->Kvarter ?></td>            
                    </tr>

                <?php elseif ($row->Collapse == 'c'): ?>
                <!-- We have a child row -->

                <tr class="child">
                    <td>&nbsp;</td>
                    <td><?php echo (!empty($row->URL)) ? $link1 : $link4 ?></td>
                    <td><?php echo $row->Amt ?></td>             
                    <td><?php echo $row->Aar ?></td>
                    <td><?php echo $row->Type ?></td>
                    <td><?php echo $row->Gade ?></td>            
                    <td><?php echo $row->Kvarter ?></td>           
                </tr>

            <?php else: ?>
            <!-- We have a non-collapsible row -->

            <tr class="non">
                <td>&nbsp;</td>
                <!-- Område, link -->
                <td><?php echo $link1 ?></td>
                <td><?php echo $row->Amt ?></td>      
                <td><?php echo $row->Aar ?></td>
                <td><?php echo $row->Type ?></td>
                <td colspan="2">&nbsp;</td>
            </tr>

        <?php endif; ?>


    <?php endwhile; ?>


</table>

<?php else: ?>

    <p>Der er ingen resultater for denne søgning</p>

<?php endif; ?>
<?php endif; ?>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros