We help IT Professionals succeed at work.
Get Started

Different headlines in a table

Peter Kroman
Peter Kroman asked
on
89 Views
Last Modified: 2017-12-05
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; ?>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE