Db Related Records listed if row selected

Db Related Records listed if row selected

Nico90Nico90 Posts: 18Questions: 7Answers: 0

Hi there,

I have a Table "Products" and I want that if I select a Product on a row, a list appear under it of related Clients Money Offers for that Row Product.

It should looks like this
:
https://i.imgur.com/gjhc8px.png
https://i.imgur.com/apmLRHL.png

Could someone please provide me some code to list the related row offers wich are saved on db?

Thanks in advance,

Nico

Replies

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    Looks like you want something like this:
    https://datatables.net/examples/api/row_details.html

    Kevin

  • Nico90Nico90 Posts: 18Questions: 7Answers: 0

    Hi Kevin,

    thank you very much, the table is exactly what i was searching for.

    Now I have a question: How can i make that products from database are listed and Offers from Clients are listed when row selected?

    Thanks,

    Nico

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    In the example the row details are part of the original data returned for each row. It is possible to use ajax to request the data for the child rows. It really depends on your data, what you are returning in the initial response, etc. Please provide more details regarding the data and how you expect to obtain it.

    Kevin

  • Nico90Nico90 Posts: 18Questions: 7Answers: 0

    Hi Kevis,

    thank you very much for your important information, I have this user.php file who is using Datatable to show users who get registered from android app. Let s say me duplicate this file and call it products.php, it will show products from database and if row will selected child rows will show money offers sent from android app and saved on database.

    here the user.php:

    <?php
    session_start();
    if (!isset($_SESSION["admin"])) {
        ?>
        <script type="text/javascript">
            window.location = "index.php";
        </script>
        <?php
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="shortcut icon" href="assets/images/logo.ico" type="image/x-icon">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="description" content="">
        <meta name="author" content="">
    
        <title>Lista Utenti</title>
    
        <?php
            include "connection.php";
            include "header.php";
        ?>
    </head>
    
    <body>
        <?php
            include "sidebar.php";
            include "menu.php";
        ?>
    <div id="wrapper">
        <div class="main-content">
            <div class="row small-spacing">
                <div class="col-xs-12">
                    <div class="box-content">
                        <h4 class="box-title">Lista Utenti</h4>
                        <table id="example" class="table table-striped table-bordered display" style="width:100%">
                            <thead>
                            <tr>
                                <th>Nome</th>
                                <th>Cognome</th>
                                <th>Azienda</th>
                                <th>Telefono</th>
                                <th>Email</th>
                                <th>Tipo</th>
                                <th>Data Registrazione</th>
                            </tr>
                            </thead>
                            <tbody>
    
                            <?php
                            $res = mysqli_query($link, "select * from registration");
                            while ($row = mysqli_fetch_array($res))
                            {
                                echo "<tr>";
                                echo "<td>"; echo $row["firstname"]; echo "</td>";
                                echo "<td>"; echo $row["lastname"]; echo "</td>";
                                echo "<td>"; echo $row["company_name"]; echo "</td>";
                                echo "<td>"; echo $row["phone"]; echo "</td>";
                                echo "<td>"; ?><a href="mailto:<?php echo $row["email"]; ?>"><?php echo $row["email"]; ?> </a> <?php echo "</td>";
                                echo "<td>";
                                if($row["offer_0_1500"]=="yes")
                                {
                                    ?><span><?php echo "0-1500 KG"; ?></span><br><?php
                                }
                                if($row["offer_1500_10000"]=="yes")
                                {
                                    ?><span><?php echo "1500-10000 KG"; ?></span><br><?php
                                }
                                if($row["offer_10000_26000"]=="yes")
                                {
                                    ?><span><?php echo "10000-26000 KG"; ?></span><br><?php
                                }
                                if($row["offer_26000_46000"]=="yes")
                                {
                                    ?><span><?php echo "26000-46000 KG"; ?></span><br><?php
                                }
                                echo "</td>";
                                echo "<td>"; echo $row["registr_date_time"]; echo "</td>";
                                echo "</tr>";
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    
    </div>
        <?php
            include "footer.php";
        ?>
    </body>
    </html>
    
    

    Thanks,

    Nico

This discussion has been closed.