Link to home
Start Free TrialLog in
Avatar of Richard Lloyd
Richard Lloyd

asked on

Fancybox/Overlay data grid

I have a large table (1000 records) that is generated from a SQL database and PHP.

I have a button on each row that opens a fancybox screen overlay that contains information from another table, based on the id of the row that contains the button. This overlay table could contain 1000 records.

Therefore, the whole page could contain 1,000,000 (1000 X 1000 records), which would take too long and kill the server etc.

My code displays the 'master' row and the 'slave' rows as follows:

<?php
//master table header
echo "<table id='download' class='tablesorter'>";
echo "<thead><tr>";
echo "<th>Id</th>\n";
echo "<th>...</th>\n";
echo "<th>Order Ref</th>\n";
echo "</tr></thead><tbody>";

//master table sql
$sql= "select  [id], [orderref],.... from table";
$result=sqlsrv_query($conn, $sql);
while($row=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
$n=$n+1;

//master table content
echo "<tr>";
echo "<td>".$row['id']."</td>\n";
echo "<td>...</td>\n";


//button to show overlay with slace table
echo "<td>";
echo "<a data-fancybox data-src='#hidden-content".$n."' href='javascript:;'>".$row['orderref']."</a>";
echo "<div style='display: none;' id='hidden-content".$n."'>";

        //overlay content
        echo "<h1>Slave Table for Order ".$row['orderref']."</h1>";
        echo "<table id='slave' class='tablesorter'>";
        echo "<thead><tr>";
        echo "<th>Id</th>\n";
        echo "<th>...</th>\n";
        echo "<th>Order Ref</th>\n";
        echo "</tr></thead><tbody>";

        //slave table sql
        $sql= "select  [id], [content],.... from subtable where orderref='$orderref'";
        $result=sqlsrv_query($conn, $sql);
        while($rowslave=sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {

        //slave table content
        echo "<tr>";
        echo "<td>".$rowslave['id']."</td>\n";
        echo "<td>...</td>\n";
        echo "<td>".$rowslave['content']."</td>";
        echo "</tr>";}
        echo "</tbody>";
        echo "</table>";

        //end of overlay
echo  "</div>";
echo "</td>";

echo "</tr>";}

//endof master table
echo "</tbody>";
echo "</table>";

Open in new window


I need to find a way to display all the master rows and then only perform the SQL to retrieve the slave rows when the relevant button is clicked, 

I am not sure if this needs to be done through Ajax, or I can just run the specific  SQL query for the slave row when the button is clicked.

Any help would be appreciated
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial