We help IT Professionals succeed at work.
Get Started

Fancybox/Overlay data grid

Last Modified: 2020-03-09
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:

//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)) {

//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
Watch Question
Top Expert 2013
This problem has been solved!
Unlock 1 Answer and 1 Comment.
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

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
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