Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:53:47+00:00 2026-05-28T03:53:47+00:00

I have a report that runs and returns 366 records, each containing a thumbnail

  • 0

I have a report that runs and returns 366 records, each containing a thumbnail that is 104 x 80 px. The issue is that the report runs very slowley even though I increased the memory size.

ini_set('memory_limit', '128M');
ini_set('max_execution_time','600');

After writing the SQL query I generate the table items here

generate_table_items($query_all_items);

This then runs through and checks for the image in the columns

function generate_table_items($query){
        $columns = array();
        $resultset = array();

        $scriptname = array();
        $scriptname[0] = "/reports/all_items.php";
        $scriptname[1] = "/reports/all_items_by_value.php";
        $columncount = 0;

        $rowcost = 0;
        $rowsale = 0;

        while ($row = mssql_fetch_assoc($query)) {

            if (empty($columns)) {

                $columns = array_keys($row);
                echo '<tr><th scope="col" >'.implode('</th><th scope="col" >',get_column_name($columns)).'</th></tr>';
                $columncount = sizeof(array_keys($row));
            }
            $resultset[] = $row;

            echo '<tr><td>'.implode('</td><td>',report_image_check($row)).'</td></tr>';

            if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
                $colspan = (count($columns)-2);
                echo "<tr><th scope='row'>Documents</th><td colspan='$colspan' >";
                    $PKID = $row['ID'];

                    if($row['SumOfTotalCost'] || $row['SumOfSalePrice']){
                        $rowcost += $row['SumOfTotalCost'];
                        $rowsale += $row['SumOfSalePrice'];
                        $get_total = true;
                    }

                    $query_docs = mssql_query("select documents.* from dbo.documents where documents.Antiquities_id = $PKID") or die ('get docs query failed ' . mssql_get_last_message());
                    while($row_docs = mssql_fetch_assoc($query_docs)){
                        $document = "../documents/" . $row_docs['document'];
                        echo "<a href='$document' title='opens in a new window' target='_blank' >" . $row_docs['document'] . "</a> | ";
                    } // End while (list docs)
                    mssql_free_result($query_docs);         
                echo "</td></tr>";
                myflush();
            } // End if all items and all items by value report

        } // End While
        echo '<tr>';
        for($i=0;$i < $columncount-4;$i++){
            echo '<td>&nbsp;</td>';
        }
        echo '<td>Total Cost '. $rowcost.'</td>';
        echo '<td>Total Sale '. $rowsale.'</td>';
        echo '<td>Total Calculated Difference '. ($rowsale-$rowcost).'</td></tr>';

} // End function

function get_column_name($columns){
$newcol = array();
$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$thecount = 0;
foreach($columns as $col) {
    if($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
        // Don't list the PK
    } else {
        $newcol[] = '<img id="'.$col.'" src="../images/icons/arrow_down.png" alt="click to sort by" onclick="sortby(\''.$col.'\');"  />' . $col;
    }
$thecount++;    
}

/*if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
    $newcol[] = "documents";
}*/

return $newcol;
}

function report_image_check($row){
global $base_url, $uploaded_images_folder;
$newrow = array();
$imageext = array();

$imageext[0] = ".jpg";
$imageext[1] = ".png";
$imageext[2] = ".gif";
$imageext[3] = ".tiff";

$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$PKID = 0;
$thecount = 0;

foreach($row as $rn) {

    if(in_array(strtolower(substr($rn,-4)),$imageext)){
        $small_img_ext = substr($rn,-4);
        $small_img = substr($rn,0,strripos($rn,"."));
        $small_img = $small_img . '_140_105' . $small_img_ext;
        $newrow[] = '<a href="' . $base_url . $uploaded_images_folder . '/' . $small_img . '" title="click to zoom on image" target="_blank" ><img src="' . $base_url . $uploaded_images_folder . '/' . $rn . '" alt="" width="50px" height="50px" /></a>';
    } elseif($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
        $PKID = $rn;
    } elseif($thecount == 2 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
        $newrow[] = "<a href='../index.php?template=10&amp;PKID=$PKID' target='_blank' >$PKID (click to view)</a>";
    } else {
        $newrow[] = $rn;
    }

    $thecount++;
    myflush();
}

/*if (in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
    $newrow[] = "<a href='#&amp;PKID=$PKID' target='_blank' >Documents (click to view)</a>";
}*/

return $newrow;

} // End function

//// Flushing function
function myflush(){

ob_implicit_flush(); 
ignore_user_abort();
}

Can anyone see an issue with this code or see why it would take so long or why it crashes firefox? Would printing to pdf function work better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:53:48+00:00Added an answer on May 28, 2026 at 3:53 am

    It’ll take a long time because you’re nesting SQL queries… executing a second SQL query for every result that has been returned by the first query…. Doing a single query with a JOIN should help performance significantly.

    Printing to PDF would almost certainly be slower: you’d eithe rneed a lot of code to position everything correctly in the report yourself, or to use one of the libraries that can take HTML and render it to a PDF (as you’re already generating HTML anyway at the moment, this would be additional processing)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a report that runs at 11 o'clock every day. i have a
I have a Report Server that runs SSRS 2008 R2 Standard. This server retrieves
I have a report that runs a stored proc: EXEC ra_spProjectCalendar @Month, @Year, @ProjectID
I have a report that uses a TChart that I am maintaining. One of
I have a report that renders data returned from a stored procedure. Using profiler
I have a report that is used by a windows service and a form
I have a report that I created with Crystal Reports 2008. This report uses
I have a report that takes two parameters from a couple of text boxes
I have a report that calculates multiple date differences (in business days, not DATEDIFF)
I have a report that I'm exporting to PDF using the VS2008 version of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.