troubleshooting Question

Fancybox/Overlay data grid

Avatar of Richard Lloyd
Richard Lloyd asked on
DatabasesPHPAJAXSQL
1 Comment1 Solution49 ViewsLast Modified:
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>";

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
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros