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
DatabasesPHPAJAXSQL

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Fell

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck